Click here to Skip to main content
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

hi..
I think this will help for you..
 
http://stackoverflow.com/questions/10151680/upload-file-on-ftp[^]
  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 Zoltán Zörgő 300
1 Peter Leow 160
2 BillWoodruff 120
3 CHill60 100
4 bling 80
0 Sergey Alexandrovich Kryukov 9,423
1 OriginalGriff 6,891
2 Peter Leow 4,692
3 Zoltán Zörgő 4,344
4 CHill60 2,932


Advertise | Privacy | Mobile
Web01 | 2.8.150129.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