Quantcast
Channel: System.Net.FtpClient
Viewing all 741 articles
Browse latest View live

New Post: FtpClient on wifi

$
0
0
I am having issues with ftpClient. The connect method works but then FileExists throws a time out exception. This happens only on Wifi

New Post: Separate trace listener per instance?

$
0
0
It's not possible in its current form. My recommendation would writing a custom TraceListener that directed data based on the Thread ID or parent Process ID.

New Post: Changing access right to file

$
0
0
How to change rights to file on the server. I use the Execute but I get error: CHMOD not understood
if (!(reply = conn.Execute("chmod 666 file.txt")).Success)
{
    throw new FtpCommandException(reply);
}

New Post: Changing access right to file

$
0
0
There's already a set of methods for doing this. You're missing the SITE command (chmod is a native FTP command). That said, it doesn't mean the server will support chmod but assuming it does the provided methods in FTP client should work fine. If you still wanted to do it with the Execute() method your code would need to look something like this:
if (!(reply = conn.Execute("SITE chmod 666 file.txt")).Success)

New Post: Windows 8.1 hangs randomly

$
0
0
We are auto uploading mixed items from about 20 machines. I have one windows 8.1 machine that after a random period of time hangs. It apparently opens the stream, then hangs, as there is a 0 length file left on the server. Over the course of 15 minutes, there is probably 350K data uploaded.

This is compiled using dotnet 2.0, which I don't feel is the issue. This issue happens with the latest code, as well as code from 2012, not sure which version.

This is a partial trace from when this hangs at 150 etc. I really don't know, after the 150 Accepted data connection, whether those Disposing lines are from the following external calls from elsewhere, or what. Pond_2_CalHistory1.png is a zero length file on the server.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 3 of 50 allowed.
220-Local time is now 16:09. Server port: 21.
220-This is a private system - No anonymous login
Disposing FtpSocketStream...
Disposing FtpClient object...
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
AUTH TLS
234 AUTH TLS OK.
Time to activate encryption: 0h 0m 0s, Total Seconds: 0.0781928.
USER RockyG@aercon.net
331 User RockyG@aercon.net OK. Password required
PASS <omitted>
230 OK. Current restricted directory is /
PBSZ 0
200 PBSZ=0
PROT P
200 Data protection level set to "private"
Text encoding: System.Text.ASCIIEncoding
PWD
257 "/" is your current location
CWD /
250 OK. Current directory is /
TYPE I
200 TYPE is now 8-bit binary
SIZE Pond_2_CalHistory1.png
213 13818
PASV
227 Entering Passive Mode (162,243,220,235,131,245)
STOR Pond_2_CalHistory1.png
150 Accepted data connection
Disposing FtpClient object...
Disposing FtpClient object...
Disposing FtpSocketStream...
Disposing FtpSocketStream...
Disposing FtpClient object...
I am considering using the BeginOpenWrite asyncronous methods, but I suspect that with all the mutex thread safety that It will end up hanging on that. Thoughts on solutions?

New Post: Text files get truncated

$
0
0
I am trying to write some code that copies some .txt files from an FTP server to a local directory in my asp.net web application. The code seems to run fine, but the resulting files are only partially complete and half of the file is filled with whitespace. This is the code I am using:
  Dim ftp As New FtpClient

                ftp.Host = ConfigurationManager.AppSettings("FTPserver")
                ftp.Credentials = New NetworkCredential(ConfigurationManager.AppSettings("FTPuser"), ConfigurationManager.AppSettings("FTPpassword"))

                Dim fileCount As Integer = 0

                For Each item In ftp.GetListing("/IPRT")
                    If item.Type = FtpFileSystemObjectType.Directory Then
                        For Each innerItem In ftp.GetListing("/IPRT/" & item.Name)
                            If innerItem.Type = FtpFileSystemObjectType.File Then
                                SaveStreamToFile(path & innerItem.Name, ftp.OpenRead(innerItem.FullName))
                                ftp.Rename("/IPRT/" & item.Name & "/" & innerItem.Name, "/IPRT/" & item.Name & "/Archive/" & innerItem.Name)
                                fileCount = fileCount + 1
                            End If
                        Next
                    End If
                Next
                Return fileCount
            End If
and the SaveStreamToFile method:
Public Shared Sub SaveStreamToFile(ByVal path As String, ByVal stream As Stream)
        If stream.Length <> 0 Then
            Dim bytesInStream(stream.Length - 1) As Byte
            stream.Read(bytesInStream, 0, bytesInStream.Length)
            File.WriteAllBytes(path, bytesInStream)
        End If
    End Sub

New Post: Text files get truncated

$
0
0
Aha, I just figured out the problem - I was forgetting to close the file stream. Adding
stream.Close()
at the end of my SaveStreamToFile method solves the issue.

Created Unassigned: Derived FtpClient class cannot clone connection [384]

$
0
0
When deriving FtpClient class exception is thrown in CloneConnection() method, because ClientCertificates property marked for cloning has private set accessor. My suggestion is to change accessibility level to protected.

Source code checked in, #d127c42fa011f4cbe5239cd58b1d3fb2e739949e

$
0
0
Changed FtpClient.CloneConnection from internal to protected

Source code checked in, #1759d850d3ecc865f474ce1dc41664575232a117

$
0
0
Change FtpClient.ClientCertificates to protected set accessor

Closed Unassigned: Derived FtpClient class cannot clone connection [384]

$
0
0
When deriving FtpClient class exception is thrown in CloneConnection() method, because ClientCertificates property marked for cloning has private set accessor. My suggestion is to change accessibility level to protected.
Comments: This should be addressed in the latest revision.

New Post: How to get FTP server response on upload

$
0
0
Hi,

I recently started using FtpClient library. So far so good. The only shortcoming I face now is not able to retrieve the server response after a successful file upload.

I am connecting to a Mainframe FTP server. Here is the response captured
FTP:Request from Port 2279,'STOR TEST#@$'
FTP:Response to Port 2279, '125  Sending Job to JES internal reader FIXrecfm 80'
FTP:Response to Port 2279, '250 -It is known to JES as JOB08630'
FTP:Response to Port 2279, '250  Transfer completed successfully.'
I am interested to display/parse the response code 125 and 250.

New Post: How to get FTP server response on upload

$
0
0
If you can send me a transaction log from System.Net.FtpClient (see Examples\Debug.cs) I'll look into this further.

--
JP Trosclair


New Post: How to get FTP server response on upload

$
0
0
Hi jptrosclair,

Thanks for quick reply. Here is the log. I just replaced the host name and username. What I am trying to do is to download a file, edit it and then put it back to Mainframe. I just want to make sure I capture the reply from server after uploading the file. Mainly these two lines
125 Sending Job to JES internal reader FIXrecfm 80
250-It is known to JES as JOB20556
220-FTPD1 IBM FTP CS V1R13 at ZZZZ, 14:14:31 on 2014-07-24.
220 Connection will close if idle for more than 5 minutes.
USER XXXXXXX
331 Send password please.
PASS <omitted>
230 XXXXXXX is logged on.  Working directory is "XXXXXXX.".
FEAT
211- Extensions supported
 SIZE
 MDTM
 REST STREAM
 UTF8
 LANG en*
 AUTH TLS
 AUTH GSSAPI
 CCC
 PBSZ
 PROT
211 End
OPTS UTF8 ON
501 command OPTS aborted -- no options supported for UTF8
Text encoding: System.Text.UTF8Encoding
TYPE A
200 Representation type is Ascii NonPrint
SIZE 'GDOC.MPHTST.OPI.UTILS.JCLCARD(EUICNRCN)'
550 command SIZE rejected - 'GDOC.MPHTST.OPI.UTILS.JCLCARD(EUICNRCN)' is not an HFS file
EPSV
229 Entering Extended Passive Mode (|||9108|)
RETR 'GDOC.MPHTST.OPI.UTILS.JCLCARD(EUICNRCN)'
125 Sending data set GDOC.MPHTST.OPI.UTILS.JCLCARD(EUICNRCN) FIXrecfm 80
250 Transfer completed successfully.
SITE FILEtype=JES
200 SITE command was accepted
TYPE A
200 Representation type is Ascii NonPrint
SIZE TEST#@$
550 command SIZE fails: filetype is JES
EPSV
229 Entering Extended Passive Mode (|||9109|)
STOR TEST#@$
125 Sending Job to JES internal reader FIXrecfm 80
250-It is known to JES as JOB20556
250 Transfer completed successfully.
Disposing FtpSocketStream...
Disposing FtpSocketStream...
Disposing FtpClient object...
QUIT
221 Quit command received. Goodbye.
Disposing FtpSocketStream...
Disposing FtpSocketStream...
Disposing FtpSocketStream...
Disposing FtpClient object...

Source code checked in, #a341639977be636e8cc319d9c859a08650b18f32

$
0
0
Added a FtpReply return value to the strream.Close() method for the streams from OpenRead(), OpenWrite(), OpenAppend(), etc....

Source code checked in, #d611c8a31805533ef0b95a00f54a8ab523dc7fa6

$
0
0
Changed accessor for FtpDataStream so you can cast your Stream objects to it if necessary.

New Post: How to get FTP server response on upload

$
0
0
Alright, the latest commit has a few things you'll be interested in. To use them cast the Stream object to a FtpDataStream. That should give you access to the public property CommandStatus which is a FtpReply object saved from the command used to open the data stream (STOR in the example above, so the 125 message after). This is actually an old property used internally in System.Net.FtpClient so don't change it unless you understand the consequences. The other change is the Close() method of the stream should now return the response that's read when the stream is closed, so the 250 messages you want. A better example:
static void StreamResponses() {
            using (FtpClient cl = new FtpClient()) {
                cl.Credentials = new NetworkCredential(m_user, m_pass);
                cl.Host = m_host;
                cl.EncryptionMode = FtpEncryptionMode.None;

                using (FtpDataStream s = (FtpDataStream)cl.OpenWrite("test.txt")) {
                    FtpReply r = s.CommandStatus;

                    Console.WriteLine();
                    Console.WriteLine("Response to STOR:");
                    Console.WriteLine("Code: {0}", r.Code);
                    Console.WriteLine("Message: {0}", r.Message);
                    Console.WriteLine("Informational: {0}", r.InfoMessages);

                    r = s.Close();
                    Console.WriteLine();
                    Console.WriteLine("Response after close:");
                    Console.WriteLine("Code: {0}", r.Code);
                    Console.WriteLine("Message: {0}", r.Message);
                    Console.WriteLine("Informational: {0}", r.InfoMessages);
                }
            }
        }

New Post: How to get FTP server response on upload

$
0
0
If you need more than that you'll want to hook in with a trace listener to monitor the server activity; basically parse the responses yourself.

New Post: How to get FTP server response on upload

$
0
0
Hi jptrosclair,

Thanks for quick response. I would try both options and see which works best for me.

Also thanks for the wonderful library for free. You rock... :)

New Post: How to get FTP server response on upload

$
0
0
No problem I hope these changes do what you needed.
Viewing all 741 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>