1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

C# FTP Help Needed

Discussion in 'Programming & Webmastering' started by dcf-joe, Aug 6, 2013.

  1. dcf-joe

    dcf-joe

    Joined:
    Feb 11, 2008
    Messages:
    381 (0.16/day)
    Thanks Received:
    22
    Location:
    Nebraska, USA
    I have a program that I want to make that utilizes ftp to download and upload a file to a ftp server that I made using serversfree.com.

    Here is the information that I have for the test account:
    Here is my C# code. It is not completed yet, but there is no point in completing it yet if the first part does not work:
    PHP:
    WebClient request = new WebClient();

    request.Credentials = new NetworkCredential("u669041582""*********");

    byte[] fileData request.DownloadData("ftp://u669041582@185.28.21.34/public_html/Test.txt");
    I get this error message when running my C# program:
    However, using FileZilla, I can access the ftp server just fine. According to FileZilla, that text.txt file I am trying to download has that URL. I have even set permissions to include everybody. What am I doing wrong?
     
    Last edited: Aug 6, 2013
  2. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,838 (6.26/day)
    Thanks Received:
    3,706
    Location:
    IA, USA
    I'm very certain WebClient only does HTTP. Try using FTPWebRequest:
    http://msdn.microsoft.com/en-us/library/ms229715.aspx

    You already gave the credentials so you shouldn't give them again in the URL.


    Edit: MSDN says it does support it so I'd just try removing the user from the URL keeping Credentials or doing it all in the URL (username:password).

    550 is permission denied.
     
    Last edited by a moderator: Feb 19, 2014
    dcf-joe says thanks.
    Crunching for Team TPU
  3. dcf-joe

    dcf-joe

    Joined:
    Feb 11, 2008
    Messages:
    381 (0.16/day)
    Thanks Received:
    22
    Location:
    Nebraska, USA
    I thank you for the response, but using the ftp web request nets me the same error, being that the program can not apparently find my file.

    That in itself is awkward, because FileZilla is displaying my directory without problem. If that program is able to access my ftp server, why can't my c# program?
     
  4. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,838 (6.26/day)
    Thanks Received:
    3,706
    Location:
    IA, USA
    I attached to this post the FtpClient I use in my programs. At its core, it uses FtpWebRequest but it also handles all the low level stuff that goes along with it (like setting the method). You'll also have to change the namespace in each of the files to suit your needs. I include instructions below for the MultithreadedFtpClient but if you don't want multithreading (highly recommended), you can use the FtpClient which is also in there.

    You start it off with something like this (note the caps lock bits that need to be replaced):
    Code:
            private MultithreadedFtpClient _Ftp = null;
    
            public Main()
            {
                InitializeComponent();
    
                RefreshListView();
    
                _Ftp = new MultithreadedFtpClient(DOMAIN_NAME, USER_NAME, PASSWORD);
                _Ftp.UploadProgressChanged += new UploadProgressChangedHandler(TransferProgressChanged);
                _Ftp.DownloadProgressChanged += new DownloadProgressChangedHandler(TransferProgressChanged);
                _Ftp.DownloadDone += new DownloadDoneHandler(TransferDone);
                _Ftp.UploadDone += new UploadDoneHandler(TransferDone);
            }
    TransferProgressChanged looks something like this:
    Code:
            private void TransferProgressChanged(object sender, ProgressChangedEventArgs e)
            {
                if (this.InvokeRequired)
                    this.Invoke(new DownloadProgressChangedHandler(TransferProgressChanged), this, e);
                else
                {
                    FileInfo fi = new FileInfo(e.Source);
                    UpdateListView(fi.Name, "Transfer", Math.Round((double)e.Transferred / (double)e.Available * 100, 0) + "%");
                }
            }
    TransferDone looks something like this:
    Code:
            private void TransferDone(object sender, DoneEventArgs e)
            {
                if (this.InvokeRequired)
                    this.Invoke(new DownloadDoneHandler(TransferDone), this, e);
                else
                {
                    FileInfo fi = new FileInfo(e.Instructions.Source);
                    UpdateListView(fi.Name, "Transfer", "100%");
                    started--;
    
                    if (started == 0)
                    {
                        lblMessage.Text = "Transfer complete.";
                        Done();
                    }
                }
            }
    An upload is as simple as:
    Code:
    _Ftp.Upload(LOCAL, REMOTE);
    A download is as simple as:
    Code:
    _Ftp.Download(REMOTE, LOCAL, OVERWRITE);
    I'm hoping that will take care of it for you. I use it on a near daily basis to write files to a secure Active Directory/IIS FTP server.
     

    Attached Files:

    • ftp.zip
      File size:
      7.8 KB
      Views:
      65
    Last edited: Aug 11, 2013
    dcf-joe says thanks.
    Crunching for Team TPU
  5. dcf-joe

    dcf-joe

    Joined:
    Feb 11, 2008
    Messages:
    381 (0.16/day)
    Thanks Received:
    22
    Location:
    Nebraska, USA
    Thank You for all of your assistance Ford, but the problem was just the people I was using to host my ftp server.

    I finally decided to pay GoDaddy (not too expensive) for a hosting site, and everything is working as it should.
     
  6. japrtorres New Member

    Joined:
    Feb 18, 2014
    Messages:
    2 (0.01/day)
    Thanks Received:
    0
    I have the same issue with serversfree.com. May I know what product of GoDaddy did you actually purchased? Is it their web hosting?
     
    Last edited by a moderator: Feb 19, 2014
  7. dcf-joe

    dcf-joe

    Joined:
    Feb 11, 2008
    Messages:
    381 (0.16/day)
    Thanks Received:
    22
    Location:
    Nebraska, USA
    I had a server from GoDaddy, but had issues with them. I ultimately made an account with http://www.onlinestoragesolution.com/ for $19 a year, and it works perfectly for what I want.
     
  8. japrtorres New Member

    Joined:
    Feb 18, 2014
    Messages:
    2 (0.01/day)
    Thanks Received:
    0
    What specific product of GoDaddy is that? May I ask for a link of it? And what problem did yout encounter?

    The thing is I'll be uploading data from an Arduino using a GSM/GPRS module without any PC help. Do you think GoDaddy and OnlineStorageSolution permits that because I think with ServersFree, they just permit uploading of files usinh FilleZilla. I may be wrong though.
     
  9. dcf-joe

    dcf-joe

    Joined:
    Feb 11, 2008
    Messages:
    381 (0.16/day)
    Thanks Received:
    22
    Location:
    Nebraska, USA
    The link to the GoDaddy product that I used is here: http://www.godaddy.com/hosting/web-hosting-new.aspx?ci=87227

    I had a multitude of problems with GoDaddy. Apparently, I was doing something "illegal" by just purchasing the hosting. Apparently to make a FTP server with them, I also needed to purchase their Virtual Private Network. That was becoming costly for something that I would be using on the side just to teach myself some programming principles.

    Also, the GoDaddy FTP server address used a naming convention that I could never get to work with C Sharp. I do not remember the exact address, or what made it awkward, but the physical address itself contained certain characters that would make Visual Studio freak out.

    So, I used Online Storage Solutions, which was cheap. I believe it was 19 USD for one entire year.

    As far as if it will work for you, I can not tell you for sure. I use it to store to and retrieve from .txt files that I use in my C Sharp programs. It works flawlessly.
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page