Click here to Skip to main content
11,488,877 members (78,523 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-CE C# Forms FTP , +
Hi everyone!

This is my first attempt in implementing a procedure to upload files via FTP. Here is what I have so far:

private void ftpOKButton_Click(object sender, EventArgs e)
{
     String sourcefilepath = pathToFileName; 
     String ftpurl = fullFTPHostName;
     String ftpusername = ftpUserNameTextBox.Text.Trim();
     String ftppassword = ftpPasswordTextBox.Text.Trim();
 
     try
     {
          string filename = Path.GetFileName(sourcefilepath);
          string ftpfullpath = ftpurl;
          FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
          ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
 
          ftp.KeepAlive = true;
          ftp.UseBinary = true;
          ftp.Method = WebRequestMethods.Ftp.UploadFile;
 
          FileStream fs = File.OpenRead(sourcefilepath);
          byte[] buffer = new byte[fs.Length];
          fs.Read(buffer, 0, buffer.Length);
          fs.Close();
 
          Stream ftpstream = ftp.GetRequestStream();
          ftpstream.Write(buffer, 0, buffer.Length);
          ftpstream.Close();
     }
     catch (Exception ex)
     {
          MessageBox.Show(ex.Message);
     }
}

My question is how can I resolve the error I'm receiving: It is failing on this line:
Stream ftpstream = ftp.GetRequestStream();
with the error message of:
"The remote server returned an error: (550) File unavailable (e.g. file not found, no access).

I've verified the file is located in the path that I'm trying to access.

Thanks everyone!
Posted 17-Jun-13 7:31am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I don't see where you are setting the ftp.ContentLength in order to tell the server how much data to expect.

MSDN FTP Upload Example[^] has a working example, albeit for a text file, but the process is the same.
  Permalink  
Comments
joshrduncan2012 at 17-Jun-13 14:45pm
   
I can't accept this solution. I'm still getting the same message after copying what the MSDN had in it. When I login via FileZilla, it logs in fine. :(
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I used too much of the hostname, which the system didn't like. I had to go up to right before the folders began in the hostname and clip that portion off.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi Josh,
Set properties of folder to be accessible for current process.(Network credential too)

Thanks,
JMDSmile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 499
1 OriginalGriff 328
2 _Asif_ 155
3 Sascha Lefèvre 135
4 _duDE_ 121
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,375
2 Sascha Lefèvre 3,334
3 Maciej Los 2,996
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 19 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100