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 bypass email scanner?
How do I add var to a function
Delimited text to array in jscript
MySQL Query
Intranet site gives "you are not authorized" after domain controller fails
Crontab error
Excel - Trying to move the contents of 2 columns into 1 cell with some formatting.
IE v FIrefox Rendering Issue
Using Excel - How to best display date and time events in timeline or chart format?
Autotext in word 2007