io sono sempre un sacco di problemi diversi in questa funzione:errori provenienti durante il caricamento immagini su FTP
public static bool UploadToFTP(string strFileName, string strFolderName)
{
bool isUploaded = false;
string strFilename = string.Empty;
string strFtpURI = string.Empty;
string strFtpUserId = string.Empty;
string strFtpPassword = string.Empty;
byte[] buffer = null;
FileInfo oFileInfo = null;
FileStream oFileStream = null;
FtpWebRequest oFtpWebRequest = null;
try
{
strFilename = strFileName;
oFileInfo = new FileInfo(strFilename);
strFtpURI = Constants.FtpUri;
strFtpUserId = Constants.FtpUserID;
strFtpPassword = Constants.FtpPassword;
oFtpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFtpURI + "/" + strFolderName + "/" + oFileInfo.Name));
oFtpWebRequest.Credentials = new NetworkCredential(strFtpUserId, strFtpPassword);
oFtpWebRequest.Proxy = null;
oFtpWebRequest.KeepAlive = false;
oFtpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
oFtpWebRequest.UseBinary = true;
oFtpWebRequest.ContentLength = oFileInfo.Length;
int iBufferLength = 2084;
buffer = new byte[iBufferLength];
int iContentLength = 0;
oFileStream = oFileInfo.OpenRead();
try
{
iContentLength = oFileStream.Read(buffer, 0, iBufferLength);
using (Stream oStream = oFtpWebRequest.GetRequestStream())
{
while (iContentLength != 0)
{
oStream.Write(buffer, 0, iContentLength);
iContentLength = oFileStream.Read(buffer, 0, iBufferLength);
}
isUploaded = true;
FtpUpload.TotalKBFilesUploaded = FtpUpload.TotalKBFilesUploaded + (int)(oFileInfo.Length/1000);
}
}
catch (Exception ex)
{
}
finally
{
if (oFtpWebRequest != null)
{
oFtpWebRequest.Abort();
oFtpWebRequest = null;
}
if (buffer != null)
{
buffer = null;
}
if (oFileStream != null)
{
oFileStream.Close();
oFileStream.Dispose();
}
}
}
catch (Exception ex)
{
}
finally
{
oFileInfo = null;
}
return isUploaded;
}
Questo è il caricamento 1000s di immagini su FTP, e questo methos viene chiamato in modo multi-threaded.
Diversi errori sono:
===================================== ==================
Messaggio: L'operazione è scaduta
traccia di errore: a System.Net.FtpWebRequest.CheckError() al sistema. Net.FtpWebRequest.GetRequestStream()
====================================== =================
messaggio di errore: Impossibile connettersi al server remoto
Errore Traccia: a System.Net.FtpWebRequest.CheckError() in System.Net.FtpWebRequest.GetRequestStream()
=== ================================================== ==
Messaggio di errore: La connessione sottostante è stata chiusa: si è verificato un errore imprevisto su una ricezione.
Errore Traccia: a System.Net.FtpWebRequest.CheckError() in System.Net.FtpWebRequest.SyncRequestCallback (obj Object) al System.Net.CommandStream.Abort (Exception e) a System.Net.FtpWebRequest.FinishRequestStage (RequestStage stadio) a System.Net.FtpWebRequest.GetRequestStream()
================================ ========
Messaggio di errore: impossibile scrivere i dati sulla connessione di trasporto: un tentativo di connessione non è riuscito perché la parte connessa non ha rispondere correttamente dopo un periodo di tempo, o la connessione stabilita non è riuscita perché l'host connesso non è riuscito a rispondere ond.
errore Trace: a System.Net.Sockets.NetworkStream.Write (Byte [] tampone, offset Int32, Int32 dimensione) a System.Net.FtpDataStream.Write (Byte [] tampone, offset Int32, Int32 dimensioni) ================================================= ======
Questi sono alcuni errori provenienti dallo stesso metodo che ho recuperato dal file LOG.
Qualche idea di cosa potrebbe causare questo? O devo dare qualche dettaglio in più?
Sembra che avete bisogno di parlare con il vostro ** n/w ragazzi nella vostra Org **. Vedo che tutti gli errori sono "n/w problemi di connettività" o "server non risponde" correttamente! – SridharVenkat