View previous topic :: View next topic |
Author |
Message |
xXHoTNoSXx How do I cheat?
Reputation: 0
Joined: 25 Nov 2011 Posts: 2
|
Posted: Fri Nov 25, 2011 11:19 am Post subject: [C#] Help to close conection with FTP |
|
|
Well.. I'm brazilian guy (my english is REALLY SUX)
Well²..
some time ago one user of here help me (created everything ahaha).. this dont matter..
he created everything about ftp connection to me. *I dont have more contact with he*
And i want one way to close the connection with ftp after done all.
Because i saw later if the user stay with app open the connection still online and i use free ftp host (only are possible 5 users per time online), the way to fix it is close/end connection after "use" the app..
Probably one way to fix it is..
Quote: | FTP.GetResponse().Close; |
But i tried this and anothers codes to close the connection but one stupid error happen and i dont know how fix ;s
the error: (spanish)
Quote: | Error 1 Sólo se pueden utilizar las expresiones de objeto assignment, call, increment, decrement y new como instrucción |
(stupid, stupid, stupid.......)
could someone tell me a method to help me solve this stupid problem?
Believe .. I really tried to find.
|
|
Back to top |
|
 |
xXHoTNoSXx How do I cheat?
Reputation: 0
Joined: 25 Nov 2011 Posts: 2
|
Posted: Fri Nov 25, 2011 9:49 pm Post subject: |
|
|
like this?
Quote: | You can only use the object expressions assignment, call, increment, decrement, and new as instruction |
|
|
Back to top |
|
 |
Unbr0ken Advanced Cheater
Reputation: 2
Joined: 10 Aug 2011 Posts: 67
|
Posted: Sat Nov 26, 2011 12:16 am Post subject: |
|
|
Hi Tiago...
Have you tried start the sesion with "KeepAlive = false"?
You must set the "KeepAlive = false" in the FtpWebRequest, like:
Code: | FtpWebRequest _Request = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileName));
_Request.KeepAlive = false;
//etc... |
By default KeepAlive is true, where the control connection is not closed after a command is executed.
If KeepAlive is false, the session will be closed automatically after 3 minuts +-...
In case that doesn't work... you must handle the ftp conections with the sockets of C#.
Regards.
|
|
Back to top |
|
 |
xXHoTNoSXx How do I cheat?
Reputation: 0
Joined: 25 Nov 2011 Posts: 2
|
Posted: Sat Nov 26, 2011 9:47 am Post subject: |
|
|
Hello
well.. i use:
Quote: | FtpWebRequest FTP = FtpWebRequest.Create(new Uri(string.Format("ftp://{0}:21/{1}/{2}", Host, RemoteFolder, RemoteFile))) as FtpWebRequest;
FTP.Credentials = new NetworkCredential(FTPUserID, FTPUserPwd);
FTP.KeepAlive = false;
etc... |
Dont have error on debug time or when compiled..
but how will I know that has been disconnected/closed?
Have one small code to know if are closed the connection? (can help me?)
(1º question: i need use the "keepalive" all times that have like..?)
Quote: | FtpWebRequest FTP = FtpWebRequest.Create ... |
and thanks..for everything.
EDIT
i was looking more about "keepalive" and...
Quote: | When the KeepAlive property is set to false, the control connection is closed when you call the Close method. |
how is this correct method to close? really need? or when are set to "false" really will close in 3min+-?
|
|
Back to top |
|
 |
Unbr0ken Advanced Cheater
Reputation: 2
Joined: 10 Aug 2011 Posts: 67
|
Posted: Sat Nov 26, 2011 3:06 pm Post subject: |
|
|
Check this link.
In the property: KeepAlive:
Quote: | Gets or sets a Boolean value that specifies whether the control connection to the FTP server is closed after the request completes. |
So... yes, you must set it to false each time you declare a FtpWebRequest variable, please read this also.
|
|
Back to top |
|
 |
xXHoTNoSXx How do I cheat?
Reputation: 0
Joined: 25 Nov 2011 Posts: 2
|
Posted: Sat Nov 26, 2011 7:07 pm Post subject: |
|
|
yes, I had read the two
but then do not need a method to close the connection (even with the keepalive on "false")?
Just keepalive = false; will close/end connection with ftp?
or will need another code to close?
thanks.
|
|
Back to top |
|
 |
Unbr0ken Advanced Cheater
Reputation: 2
Joined: 10 Aug 2011 Posts: 67
|
Posted: Sat Nov 26, 2011 8:34 pm Post subject: |
|
|
xXHoTNoSXx wrote: | Just keepalive = false; will close/end connection with ftp? |
I think i've explained enough.
Last edited by Unbr0ken on Tue Nov 29, 2011 4:31 am; edited 1 time in total |
|
Back to top |
|
 |
xXHoTNoSXx How do I cheat?
Reputation: 0
Joined: 25 Nov 2011 Posts: 2
|
Posted: Sat Nov 26, 2011 9:45 pm Post subject: |
|
|
dont are possible use just
FTP.close();
code dont know the "close();" after "ftp."
Quote: | 'System.Net.FtpWebRequest' no contiene una definición de 'close' ni se encontró ningún método de extensión 'close' que acepte un primer argumento de tipo 'System.Net.FtpWebRequest' (¿falta una directiva de uso o una referencia de ensamblado?) |
But well.. if just "keepalive = false;" REALLY will end/disconnect connection with FTP.. are all ok
tomorrow or after tomorrow i will test the code in my other computer
last thing
have one small code to show one msg only for i see after how long or when the connect really has been disconnected?
BTW: i send one email to "unbr0ken @ live . com"
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Sun Nov 27, 2011 4:44 pm Post subject: |
|
|
FtpWebRequest doesn't handle the actual socket, it just has request properties for timing out. The response object to your request (FtpWebRespone) is what holds the connection.
Call Close on your Response objects when you are done with them.
_________________
- Retired. |
|
Back to top |
|
 |
|