I'm trying to get an FTP transfer in code to speed test something, but for some reason no matter how I try, it ends up taking twice as long as if I do it through console?
I'm transferring a 100MB file, here's the result of the console transfer:
However, the two methods I've tried - raw C# first and using a library (http://www.enterprisedt.com/products/edtftpj/) (second) take 70+ seconds...
Anybody point out what I'm doing wrong?
EDIT: Changing between active/passive and binary/ASCII didn't make any difference. The file is just a large file of emptiness created using "fsutil file createnew".
I'm transferring a 100MB file, here's the result of the console transfer:
Code:
ftp> put FTP_UP.txt
200 Port command successful
150 Opening data channel for file transfer.
226 Transfer OK
ftp: 104857600 bytes sent in 40.57Seconds 2584.42Kbytes/sec.
ftp>
However, the two methods I've tried - raw C# first and using a library (http://www.enterprisedt.com/products/edtftpj/) (second) take 70+ seconds...
Code:
public static TimeSpan PutFile(Uri serverUri, string LocalFile, string Username, string Password)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.KeepAlive = false;
request.Credentials = new NetworkCredential(Username, Password);
DateTime timeStart = DateTime.Now;
Stream requestStream = request.GetRequestStream();
const int BUFFERSIZE = 4096;
byte[] buffer = new byte[BUFFERSIZE];
FileInfo uploadfile = new FileInfo(LocalFile);
FileStream fs = uploadfile.OpenRead();
while ((fs.Read(buffer, 0, BUFFERSIZE)) != 0)
{
requestStream.Write(buffer, 0, BUFFERSIZE);
}
requestStream.Close();
fs.Close();
DateTime timeStop = DateTime.Now;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
return timeStop - timeStart;
}
Code:
public static TimeSpan PutFile(IPAddress serverUri, string LocalFile, string Username, string Password)
{
FTPClient ftp = null;
ftp = new FTPClient(serverUri);
ftp.Login(Username, Password);
ftp.ConnectMode = FTPConnectMode.ACTIVE;
ftp.TransferType = FTPTransferType.BINARY;
DateTime timeStart = DateTime.Now;
ftp.Put(LocalFile, "FTP_UP.txt");
DateTime timeStop = DateTime.Now;
ftp.Quit();
return timeStop - timeStart;
}
Anybody point out what I'm doing wrong?
EDIT: Changing between active/passive and binary/ASCII didn't make any difference. The file is just a large file of emptiness created using "fsutil file createnew".
Last edited: