# C# FTP Help Needed



## dcf-joe (Aug 6, 2013)

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:


> FTP IP:	185.28.21.34
> FTP Hostname:	joshuaserverconnect.com
> FTP Username:	u669041582
> FTP Password:	••••••••••
> ...



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:

```
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:


> The remote server returned an error: (550) File unavailable (e.g., file not found, no access).



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?


----------



## FordGT90Concept (Aug 6, 2013)

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.


----------



## dcf-joe (Aug 11, 2013)

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?


----------



## FordGT90Concept (Aug 11, 2013)

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):

```
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:

```
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:

```
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:

```
_Ftp.Upload(LOCAL, REMOTE);
```
A download is as simple as:

```
_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.


----------



## dcf-joe (Aug 24, 2013)

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.


----------



## japrtorres (Feb 18, 2014)

dcf-joe said:


> 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.



I have the same issue with serversfree.com. May I know what product of GoDaddy did you actually purchased? Is it their web hosting?


----------



## dcf-joe (Feb 19, 2014)

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.


----------



## japrtorres (Feb 19, 2014)

dcf-joe said:


> 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.


 
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.


----------



## dcf-joe (Feb 20, 2014)

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.


----------

