Microsoft
Software
Hardware
Network
Question : how to be able to push several files to ftp server, i receive 503 on fifth file, how to reuse ftp connection?
hello experts,
i'm trying to push a list of files to ftp.
the problème is that my uploads stop on the fifth file, i receive a 503 error. i've browse internet with the prob, some people sais to reuse the ftp connection but in my situation i dont know how to doit.
Here's my code:
i'm trying to loop around file names, but if the ftpwebrequest needs the file in order to be created how can i reuse the same if i'm pushing different files ?`
private void PushAllFiles()
{
System.IO.Stream requestStream = null;
System.IO.FileStream fileStream = null;
System.Net.FtpWebResponse uploadResponse = null;
string _user = _theConfig.FTPEcologDepotU
ser();// FTPGatewayUser();
string _pass = _theConfig.FTPEcologDepotP
ass();
string _server = _theConfig.FTPEcologDepotS
erver();
string _repo = _theConfig.FTPEcologDepotS
erverRepo(
);
try
{
foreach (string fileName in _theFilesToPush)
{
Thread.Sleep(1000);
// file to upload
string uploadUrl = "
ftp://
" + _server + _repo + "/" + Path.GetFileName(fileName)
;
// setting request
FtpWebRequest uploadRequest = (FtpWebRequest)WebRequest.
Create(upl
oadUrl);
uploadRequest.Credentials = new NetworkCredential(_user, _pass);
uploadRequest.Method = WebRequestMethods.
Ftp.Uplo
adFile
;
uploadRequest.Proxy = null; // UploadFile is not supported through an Http proxy // so we disable the proxy for this request.
requestStream = uploadRequest.GetRequestSt
ream();
fileStream = File.Open(fileName, FileMode.Open);
byte[] buffer = new byte[1024];
int bytesRead;
while (true)
{
bytesRead = fileStream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
requestStream.Write(buffer
, 0, bytesRead);
}
// The request stream must be closed before getting
// the response.
requestStream.Close();
uploadResponse = (FtpWebResponse)uploadRequ
est.GetRes
ponse();
Console.Write("\nUpload complete:" + uploadResponse);
Thread.Sleep(1000);
}
}
catch (UriFormatException ex)
{
Console.Write("\nFtpUpload
->Upload : Uriformat" + ex.Message);
throw new EplanException("error uploading ftp file");
}
catch (IOException ex)
{
Console.Write("\nFtpUpload
->Upload : " + ex.Message);
throw new EplanException("error uploading ftp file");
}
catch (WebException ex)
{
Console.Write("\nFtpUpload
->Upload : " + ex.Message);
throw new EplanException("error uploading ftp file");
}
finally
{
if (uploadResponse != null)
uploadResponse.Close();
if (fileStream != null)
fileStream.Close();
if (requestStream != null)
requestStream.Close();
}
}
thank you in advance for a code which will reuse the connections.
Answer : how to be able to push several files to ftp server, i receive 503 on fifth file, how to reuse ftp connection?
Give this a try, see if it gives you some ideas:
@echo off
set DestinationDirectory=X:\
for /F "tokens=*" %%A in ('dir /b /s "c:\*_daily"') do (
robocopy "%%A" %DestinationDirectory%" /S
)
~bp
Random Solutions
Best database for a manufacturing warehouse
How to set up IIS to send alerts in the event of a system failure
want distinct, newest rows
TSQL Scalar Function using select inside the function & excluding date
PNG Image Lib , can't compile with D2010
select within exec
upgrading compatability level in SQL 2000
install PDFlib on FreeBSD
t-sql arithmetic overflow error on update
Slow upload behind ISA Server 2004