C# Upload File to FTP

Posted on 2011-11-01
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 so I changed username to be '' and I also tried '

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 37

    Expert Comment

    by:Gerwin Jansen
    Credentials are set this way:

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

    See here for a complete example.
    LVL 9

    Expert Comment

    LVL 12

    Accepted Solution

    The following should work with you:

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    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…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now