Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - [vb.net] errore upload file con xp
Forum - C# / VB.NET - [vb.net] errore upload file con xp

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
marco444 (Normal User)
Rookie


Messaggi: 55
Iscritto: 28/03/2010

Segnala al moderatore
Postato alle 12:58
Mercoledì, 21/04/2010
ciao a tutti,
sto provando a fare l'upload di un file exe in un ftp con questo codice:


Private WithEvents up As New System.Net.WebClient


up.Credentials = New System.Net.NetworkCredential("", "")
Dim address As Uri = New Uri("ftp://")

up.UploadFile(address, ("C:\"))


in win 7 funziona perfettamente, anche con vista, ma con xp mi da questo errore:

http://www.allfreeportal.com/imghost2/images/710877errore.jpg


perchè secondo voi?


Ultima modifica effettuata da marco444 il 21/04/2010 alle 16:24
PM Quote
Avatar
marco444 (Normal User)
Rookie


Messaggi: 55
Iscritto: 28/03/2010

Segnala al moderatore
Postato alle 14:18
Mercoledì, 21/04/2010
mi correggo, il problema si verifica solo con il .net 2.0

PM Quote
Avatar
NetProgrammer (Member)
Pro


Messaggi: 175
Iscritto: 28/06/2008

Segnala al moderatore
Postato alle 17:40
Mercoledì, 21/04/2010
Dallo screen dell'errore si capisce che c'è una violazione di protocollo, inoltre il codice che hai postato è incompleto e contenenti errori,infatti se non mi sbaglio non vedo alcun pezzo di codice che tenta di gestire una connessione ftp efficiente!!
Comunque da quello che ho capito l'errore risiede in address,in quanto non viene specificato nessun dominio ftp.
Comunque se analizzi l'errore nel testo dell'errore ti dovrebbe dire anche la riga che l'ha generato.

Ultima modifica effettuata da NetProgrammer il 21/04/2010 alle 17:41
PM Quote
Avatar
marco444 (Normal User)
Rookie


Messaggi: 55
Iscritto: 28/03/2010

Segnala al moderatore
Postato alle 18:26
Mercoledì, 21/04/2010
ma perchè il codice che uso va bene in qualunque versione del .net, tranne che nella 2.0

PM Quote
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Segnala al moderatore
Postato alle 18:44
Mercoledì, 21/04/2010
Spiegazione:
Testo quotato

Essentially requests are made by opening a connection, making a number of them then closing it. In this occurance, the connection times out but is not recognized as closed and thus a new connection is not established for the next request and an error is returned.

Setting the keepalive to false sets it to close and reopen connections for each request. This taxes the server quite a bit more (some 7 connections for each new request). I would welcome any solutions to this error that don't involve this much traffic but I have yet to find any and am reluctant to write around it.

The suggestions I found indicated that setting the keepalive should solve it, yet some suggested setting the http version to 1.0.

There are variations in how the 1.0 and 1.1 versions of how the protocol work. Officially, the version 1.0 doesn't support keep-alives, however some implementations do support it.

.Net is designed to use http 1.1 to make requests which encourages persistant connections. It is more likely you'll avoid the error by forcing the use of the 1.0 protocol as it didn't take advantage of persistant connections (multiple requests per connection), however I cannot say either way as to whether the error won't still occur with the version set as 1.1

For example, leaving it set to use the 1.1 protocol will likely not try to keep the connection alive, but may still try to send more requests per connection which may cause the error to happen, just less frequently.

Unfortunately I cannot track down the original microsoft documentation on this issue as it seems to have disappeared, so outside of studying the documented http 1.0 and 1.1 versions of the protocol, comparing them and studying the .net implementation, there isn't much you can do aside from setting both to avoid the error.


Fonte:
http://geekswithblogs.net/Denis/archive/2005/08/16/50365.aspx

Sembra un bug del Framework effettivamente...

PM Quote
Avatar
marco444 (Normal User)
Rookie


Messaggi: 55
Iscritto: 28/03/2010

Segnala al moderatore
Postato alle 23:59
Mercoledì, 21/04/2010
possibile soluzione?
magari un codice simile ma con le stesse funzioni, oppure un aggiornamento, o un codice per il 2.0, qualcosa per favore.

PM Quote
Avatar
marco444 (Normal User)
Rookie


Messaggi: 55
Iscritto: 28/03/2010

Segnala al moderatore
Postato alle 15:48
Giovedì, 22/04/2010
nessuno??

PM Quote
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Segnala al moderatore
Postato alle 19:10
Giovedì, 22/04/2010
Testo quotato

The suggestions I found indicated that setting the keepalive should solve it, yet some suggested setting the http version to 1.0.


PM Quote
Avatar
marco444 (Normal User)
Rookie


Messaggi: 55
Iscritto: 28/03/2010

Segnala al moderatore
Postato alle 8:52
Venerdì, 23/04/2010
l'ho provato, ma non mi sembra che faccia al caso mio, non posso metterci nome utente e pass, però ho trovato questo:
//get the contents of the file you want to upload

byte[] fileContents;

string FinalFile = @"c:\autoexec.bat";
using(System.IO.FileStream fs = new System.IO.FileStream(FinalFile, System.IO.FileMode.Open)) {

  fileContents = new byte[fs.Length];
  fs.Read(fileContents, 0, (int)fs.Length);

}

//get the filename, append it to the URL
System.IO.FileInfo fi = new System.IO.FileInfo(FinalFile);

//FTPServerURI must be in the format of:

//ftp://user:password@ftp.myserver.com:21/path/to/upload/fo ...
string uri = string.Format("{0}{1}", FTPServerURI, fi.Name);

//now we have:

//ftp://user:password@ftp.myserver.com:21/path/to/upload/fo ...autoexec.bat

//create the ftp request
System.Net.WebRequest request = System.Net.FtpWebRequest.Create(uri);

//state that we uploading the file
request.Method = System.Net.WebRequestMethods.Ftp.UploadFile;

//get the request stream
using (System.IO.Stream stm = request.GetRequestStream()) {

  //write the contents of the file up

  stm.Write(zipContents, 0, zipContents.Length);

}

puo essere valido anche se è per c?

PM Quote
Pagine: [ 1 2 ] Precedente | Prossimo