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
How to use reporting in VB.NET ?
c# last execution time of a process and kiling the last process of the same application
SQL 2005 mirroring
Need to see traffic across WAN
Excluding the milliseconds from a returned date
Ways to prolong lifespan of netbook laptop & PDA phone battery
How to preserve "emergency" resources in Windows Server 2003 R2 x64
Ms sql query last order by customer
The network path was not found while connecting to remote computer with performance monitor
jQuery accordion overlaps IE7 footer