C# Upload File to FTP

Posted on 2011-11-01
Medium Priority
Last Modified: 2013-12-16
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);
Stream ftpstream = ftpWebRequest.GetRequestStream();					ftpstream.Write(buffer, 0, buffer.Length);

Open in new window

Question by:ChrisMDrew
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 37062023
Credentials are set this way:

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

See here for a complete example.
LVL 12

Accepted Solution

Mohamed Abowarda earned 2000 total points
ID: 37105025
The following should work with you:

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month17 days, 3 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question