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.
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
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();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ftpWebRequest.Credentials = new NetworkCredential(ftpUserI
See here for a complete example.