Link to home
Start Free TrialLog in
Avatar of ChrisMDrew
ChrisMDrew

asked on

C# Upload File to FTP

Just having a few problems uploading a file to an FTP site using C# / FtpWebRequest as shown.  I get an exception thrown of

The remote server returned an error: (530) Not logged in.

I did read somewhere about adding the domain to the username but this did not help - forexample my domain is ftp.remotedomain.com so I changed username to be 'Customer@remotedomain.com' and I also tried 'Customer@ftp.remotedomain.com.

Not sure what the problem is so any suggestions please.
// URI including port 
string uri = "ftp://" + auditScannerDefinition.FTPSiteBackup + ":" + auditScannerDefinition.FTPPortBackup.ToString() + "/" + targetFile;

// Create the FTP request
FtpWebRequest ftpWebRequest =(FtpWebRequest)FtpWebRequest.Create(uri);

// Credentials
ftpWebRequest.Credentials = new System.Net.NetworkCredential("Customer", auditScannerDefinition.FTPPasswordBackup);
					ftpWebRequest.KeepAlive = true;					ftpWebRequest.UseBinary = true;
ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;

// Get the input file
FileStream fs = File.OpenRead(tempFile);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftpWebRequest.GetRequestStream();					ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();

Open in new window

Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Credentials are set this way:

ftpWebRequest.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

See here for a complete example.
ASKER CERTIFIED SOLUTION
Avatar of Brad Brett
Brad Brett
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial