Page 1 of 2 12 LastLast
Results 1 to 40 of 46

Thread: To all who's doing FTP: Here's an FTP class to simplify things drastically

  1. #1

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Thumbs up [new update] Here's an FTP class to simplify things drastically

    ok this is the reinvented version I promised long time ago.
    there's a vbs script file that shows how to use the class file.
    see, no events needed. well, you can use the events too, by using the
    wscript.connectobject method.


    VB Code:
    1. 'To use this class, declare it like this
    2. Dim WithEvents ftpConn As ftpConnection
    3.  
    4. 'Create a new instance of it
    5. Set ftpConn = New ftpConnection
    6.  
    7. 'To connect
    8. ftpConn.User = "Anonymous"
    9. ftpConn.Password = "Guest"
    10. ftpConn.Passive = True ' Use passive mode
    11. ftpConn.RemoteHost = "ftp.ftpsite.com"
    12. ftpConn.RemotePort = 21 'default is 21
    13. ftpConn.Connect

    LISTING FILES + INFO
    VB Code:
    1. 'lstFiles is a listbox
    2.     If ftpConn.CommandState = CMD_LOGGED_IN Then
    3.         'if you want just a list of names, use ftpConn.GetFileList()
    4.         If ftpConn.GetFileListInfo() = True Then
    5.             Do Until ftpConn.ListParser.IsParsed
    6.                 DoEvents
    7.             Loop
    8.             Dim i As Long
    9.             lstFiles.Clear
    10.             For i = 0 To ftpConn.ListParser.FileCount - 1
    11.                 lstFiles.AddItem ftpConn.ListParser.fileList(i, ftpConn.ListParser.ColumnCount - 1)
    12.             Next
    13.         Else
    14.             MsgBox "FAILED"
    15.         End If
    16.     Else
    17.         MsgBox "NOT LOGGED IN"
    18.     End If

    OK, so here's the thing. My ftp class no longer reads from/writes to files. You've to supply the data when it's needed (through the appropriate raised events).

    DOWNLOAD
    VB Code:
    1. 'You must declare a dataConnection object
    2. Dim dataConn As dataConnection
    3.  
    4. 'Now you need to allocate a data socket
    5. Set dataConn = ftpConn.NewDataConnection(ftpConn.IsPassive)
    6. dataConn.DataType = TYPE_BINARY ' works for all types of files
    7.  
    8. 'To download
    9. If dataConn.Initiate(True) Then 'true to asynchronously connect
    10.     dataConn.StartTransfer TRANSFER_DOWNLOAD, "download.txt"
    11. End If
    12.  
    13. 'Incoming data event
    14. Private Sub dataConn_IncomingData(bytes As Long)
    15.     Dim s As String
    16.     s = dataConn.GetData() 'so now s holds (part of) the data
    17. End Sub
    18.  
    19. 'If you're writing s to a file and don't know when to stop, use this event
    20. Private Sub dataConn_StateChanged()
    21.     If dataConn.DataState = DATA_DISCONNECTED Then
    22.         dataConn.Dispose
    23.         Set dataConn = Nothing
    24.         'And close your file here
    25.     End If
    26. End Sub

    UPLOAD
    VB Code:
    1. 'You must declare a dataConnection object
    2. Dim dataConn As dataConnection
    3.  
    4. 'Now you need to allocate a data socket
    5. Set dataConn = ftpConn.NewDataConnection(ftpConn.IsPassive)
    6. dataConn.DataType = TYPE_BINARY ' works for all types of files
    7.  
    8. 'To upload
    9. If dataConn.Initiate(True) Then 'true to asynchronously connect
    10.     dataConn.StartTransfer TRANSFER_UPLOAD, "download.txt"
    11. End If
    12.  
    13. 'Upload data in this event, it'll be called every time the previous data
    14. 'chunk is fully uploaded
    15. Private Sub dataConn_NeedData()
    16.     If dataConn.DataState = DATA_TRANSFERRING Then
    17.         dataConn.SendData "Hello, World!" ' replace this data with sth else
    18.     End If
    19. End Sub
    20.  
    21. 'When you're done uploading, you can close the connection here
    22. Private Sub dataConn_SendComplete()
    23.     'If all data is uploaded then
    24.         'dataConn.Disconnect 'disconnect if you're done
    25.     'End If
    26. End Sub

    CLEANING UP
    VB Code:
    1. 'so you want to quit, do this.
    2. ftpConn.Quit 'Kiss FTP Server Bye bye
    3. ftpConn.Dispose 'Disconnect the sockets, destroy used objects
    4. dataConn.Dispose
    5. Set dataConn = Nothing
    6. Set ftpConn = Nothing

    To do other stuffs, like renaming/deleting/creating file/directory, etc, check out the class file. If there's some methods not provided, you can always use the SendCommand to send your own commands. Consult a FTP document.

    The attached file has demo codes, so you can see how things work. And finally, please do credit me whenever you use part or all of my codes.

    Thank you.
    Attached Files Attached Files
    Last edited by jian2587; Jan 11th, 2008 at 05:37 PM. Reason: New update
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  2. #2
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Originally posted by jian2587
    Okay, shouldn't this be in the CodeBank or wut?
    Well, I dont think anyone would go there often, once they've a
    problem, they go here. To look for codes, they goto PSC instead.
    you shd tell this to the moderators


    Thanks for the post.(havent tested it though)

  3. #3
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    your wrong, its suprising how many people do visit the codebank. The other day i posted about 6 examples, and with an hour i had over 15 views for each thread.

  4. #4
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Originally posted by Madboy
    your wrong, its suprising how many people do visit the codebank. The other day i posted about 6 examples, and with an hour i had over 15 views for each thread.

    then, Report it to the mods.

    they would move it anyways.

  5. #5

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    K, so it ain't a big mistake, huh?

    These days I see some ppl having probs with FTP in this forum.
    That's why I put it here.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  6. #6
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    If they did a Search for FTP, then they would find it in the code bank.

  7. #7
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    although the large amount of people who dont bother to use the Search facility would not be aware of it.

    Lets see what the mods say eh

  8. #8
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Either way, if they dont do a Search, it will get buried here faster than if it was put in the Code Bank. It will be off the first page by tonight.

  9. #9
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294
    is it possible to use this with a progress bar? cause it'll be useless to upload a big file without knowing when it will be done. anyone know a winsock version out there with a progress bar?

  10. #10
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Originally posted by Whatupdoc
    is it possible to use this with a progress bar? cause it'll be useless to upload a big file without knowing when it will be done. anyone know a winsock version out there with a progress bar?
    I was wondering the same thing... I would need a way to detect the progress...
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  11. #11
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    Search the forum, I helped someone make one. So I know it's out there. Search for FTP Randem, youre sure to find it.

  12. #12
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    if you know the size of the upload/download set the pb.max to the files size and set pb.value to how much send/received

    assuming pb is a progressbar
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  13. #13

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    Well, my class doesn't provide that.
    But u can do it urself.
    For example:
    VB Code:
    1. 'Download file
    2. objFTPC.OpenDataConnection
    3. Do Until objFTPC.DataState = DS_INITIATED 'Sorry it's
    4. 'DS_INITIATED, not DS_CONNECTED as previously mentioned
    5.     DoEvents
    6. Loop
    7. objFTPC.DownloadFile "readme.txt"
    8. 'When transfer is starting, the event IncomingData will fire.
    9. Private Sub objFTPC_IncomingData(bytesTotal As Long)
    10. Dim sData As String
    11. objFTPC.GetData sData, bytesTotal
    12. 'Write it on local file
    13. Put #1, , sData
    14. 'And u constantly record the data length and from there u can
    15. 'calculate your progress
    VB Code:
    1. 'To get the remote file's size
    2. objFTPC.OpenDataConnection
    3. Do Until objFTPC.DataState = DS_INITIATED
    4.     DoEvents
    5. Loop
    6. objFTPC.ListFileInfo ""
    7. 'When the data is replied, u can check it via
    8. 'objFTPC.FileInfo(Index).FileSize property

    Later I shall post an example showing almost all u can do with
    this class.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  14. #14

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Moved To The CodeBank

  16. #16

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    i have to admit, the class is full of bugs...and i did not follow the protocols correctly and fully.
    if possible, i want to do a rewrite.
    if you see me reply in a few days, that means i'm on it. if not, i may be too busy.
    totally sorry for those random quirks.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  17. #17
    New Member
    Join Date
    Mar 2007
    Posts
    2

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    What is codebank?

  18. #18

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    CodeBank is the forum you are in right now; think of it as a place to store and share codes.

    I rewrote the whole thing from scratch, with better and more streamlined codes. This also means there's no spaghetti codes and it'll be easier for you to understand the codes. (I spent hours on this non-stop, and skipped my lunch , so I hope you'll for the least credit me when you use my codes).

    I also try to follow the ftp protocol as much as is possible, but I don't provide much out-of-the-ordinary case handling. The class has methods where you can use to check out such cases, and you can take care of them yourself.

    The class now doesn't write the incoming data to the file for you, nor does it read the file when you're uploading. Events will be raised whenever there's new data (download) or data is needed (for upload). You can use GetData and SendData method of the class to do this. This is in line of OOP's guideline. The class shouldnt do too much things on its own.

    Now what's left undone is directory listing parsing. I can parse only UNIX and WINDOWS NT format (the two most widely used format). If you happen to use other formats, you have to write your own parser. I'm thinking of separating the parser as another class instead of integrating it into the ftp class. So we can implements different kinds of parser. To know which parser to use, SYST usually gives you a good idea what kind of system the ftp server is on.

    I guess I can get it done tonight, and then I also need to test and debug. When the codes are ready I'll upload it asap.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  19. #19

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    By the way, if you want to do progress kinda things, you can first get the file size by getting the file list info (then the parser will parse for you), and depending on what system the ftp server is on, the file size may be on different columns. Use the appropriate column index in calling listParser.FileList to get the size. On UNIX, it's on 5th column (column index 4). On Windows NT with MS-DOS style output, it's on 3rd column (column index 2).

    So you've the complete file size, now you can update the progress in the IncomingData event.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  20. #20

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Note: when up/downloading, the class file doesn't open/read/write the local file for you.
    When uploading, the NeedData event and SendComplete event will fire alternately, and repeatedly. You upload the data by using dataConn.SendData in the NeedData event. Send in chunks, not whole thing at once. When you're done, you can use dataConn.disconnect in the SendComplete event.
    Same thing with downloading. The IncomingData event will fire repeatedly until all data has been acquired. It'll close automatically when it's done.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  21. #21
    Lively Member
    Join Date
    Jul 2007
    Posts
    74

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    many thanks to the guy who wrote this,

    I am having problems trying to get the list of files to appear in the lstfiles textbox. When the program is running the get file list is clicked, the list box does not show any directory listings! Even changing the CWD, it does not work.

    please help

  22. #22

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Did you try logging in first? Was it successful?
    If it was, was the directory you were accessing protected? i.e. the server does not allow you to list its contents?
    If it wasn't, did you wait long enough? I'm aware that IIS ftp server on localhost is somewhat retarded when it comes to returning file list.
    I've not touched the code for a long time, however, I did remember there's a parser class that helps parse file list data. Windows NT server, Unix server, and any other kinds of servers on different platforms return the file list differently. The parser I have written is able to parse the two dominant ones only, namely NT and Unix. You may want to check what the server is by sending a SYST command.
    Also, check firewall settings?
    And try FTP passive mode if possible.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  23. #23
    Lively Member
    Join Date
    Jul 2007
    Posts
    74

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Thanks for responding

    First of all, the conection works to the FTP server and its a UNIX server. I wouldnt imagine the directories are protected as others programs can retrieve the listings and i did leave it long enough. The server is not on my computer, its actually my XBOX. The firewall is open to the connections and i did try passive mode which is just giving the same reults. I also tried using the different columbs but no results.

    Thanks
    Mathy

  24. #24

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    post some snap shots. that'll help me diagnose the problem.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  25. #25
    Lively Member
    Join Date
    Jul 2007
    Posts
    74

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    thanks mate, your help is really appreciated.

    I have taking a couple o snap shots to help


    Log on screen


    Get File List - This is the problem
    As you can see there has been 5 entries added all with no names,
    This is the root drive and there is five folders


    SYST command to show file server


    To show by changing directory, it still doesnt show the contents
    Does not show file or folder names.

    Thanks
    Mathy

  26. #26

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    i see. i'm away from my source codes now. as far as i can remember, the ftp class invokes a parser class to parse the data. i can't duplicate your situation, but i'll peek around at the parser class, and here's what i recommend while you wait. study the parser class's methods a bit and you can use a debug.print or anything to display the raw data. if you see the file list data, then it can only mean the parser didn't parse things right. if you don't see anything, you can check the data socket's incomingdata event in the ftp class file. you can dump them on the screen as the data pours in. if you see the file list data, then that means the data handling has got problems.

    network->data socket->ftp class->parser class->list box

    you probably wanna check at what point (which arrow) the data disappears.

    i still believe it's the parser's fault though.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  27. #27
    New Member
    Join Date
    Aug 2007
    Posts
    3

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    There is a small bug in getting the File list. The flag "ftpConn.ListParser.IsParsed" is never cleared once it is set.

    I had to make these modifications (there is perhaps a better way):
    Code:
    'Added this to ftpListParser
    Public Sub ClearIsParsed()
        bParsed = False
    End Sub
    and here:

    Code:
    'Added clear flag calls to ftpConnection
    Public Function GetFileList(Optional ByVal directory As String = "") As Boolean
        ChangeDataType TYPE_ASCII
        Me.ListParser.ClearIsParsed
        listConn = NewDataConnection(userPasv)
        If listConn.Initiate(True) = True Then
            Call listConn.StartTransfer(TRANSFER_NLST, directory)
            GetFileList = True 'oops, don't forget this
        Else
            GetFileList = False
        End If
    End Function
    
    Public Function GetFileListInfo(Optional ByVal directory As String = "") As Boolean
        GetFileListInfo = False
        ChangeDataType TYPE_ASCII
        Me.ListParser.ClearIsParsed
        Set listConn = NewDataConnection(userPasv)
        If listConn.Initiate(True) = True Then
            Call listConn.StartTransfer(TRANSFER_LIST, directory)
            GetFileListInfo = True
        Else
            GetFileListInfo = False
        End If
    End Function
    Wicked Great bit of code BTW !
    Many thanks.
    Last edited by FD 80; Aug 29th, 2007 at 05:40 PM.

  28. #28

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Oh I don't think that's a bug. It's intended to be never cleared. Because every time a file list is obtained, a new list parser class is created...or did I not? in that case, it's good you changed it
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  29. #29
    New Member
    Join Date
    Aug 2007
    Posts
    3

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Hmmm, I must of hit an instance where it wasn't re-creating the class. (Of course it is entirely possible that I just did something improper.)
    Basically I was playing around with it and added a change directory button.

    Code:
    Private Sub cmdCWD_Click()
        If Not ftpConn.ChangeDirectory(lstFiles.Text) Then
            MsgBox "Failed"
        End If
    End Sub
    I basically connected, retrieved a file list that included directories, selected a directory and changed the working directory, but when I hit Get File List again, it just displayed the last file listing. I had to hit it again to get the new list. I found by adding the modifications that the problem went away.

  30. #30

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    when i think back, the only reason I write the ftp class this way (i.e. with control socket and data socket as two separate classes) is the idea that there can be MULTIPLE ftp transfers running simultaneously. I had mentioned I've never tried doing simultaneous multiple transfers.

    Now it occurs to me the ftp protocol is designed to transfer one file at a time, per control socket connection. if that's the case, it adds unnecessary level of abstraction of complication to have the data transfer as a separate class.

    I actually have a new version, with cleaner and better codes; also, without the separate data transfer class. Basically, an ftp client class and a list parser class is all we need.

    In this newer version, programmer actually has the option of coding their ftp thing in two ways. Either use events, or do->check state->loop. The latter is for linear execution of codes, suitable for scripts...e.g. vbscripts.

    The code to initiate a transfer is easier than ever (not as easy as ftp.getfile("blah.txt"), and is intended to not to be this easy and rigid), while still retaining the flexibility.

    I'll upload the codes soon, after tidying up the example codes.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  31. #31
    New Member
    Join Date
    Aug 2007
    Posts
    3

    Thumbs up Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    I found a handy piece of file list parsing code by D. J. Bernstein http://cr.yp.to/ftpparse.html

    I adapted some of it to VB and added it to the list parser. I excluded the date/time extraction as I was more interested in name, size, folder vs file. But I am sure anyone interested can follow the link and adapt that portion of it.

    I only tested it with Unix style listing. Handles long file names alright. It now gives a collection of 3 columns ( 'd' or '-' for folder vs file, size in bytes, name).

    I have attached it here, if anyone finds it useful. (It may be a little ugly thought.)
    Attached Files Attached Files

  32. #32

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    this is awesome FD 80!

    oops i did not upload the latest codes I promised. It's a complete rewrite actually. Will do it soon.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  33. #33
    Lively Member
    Join Date
    Jul 2007
    Posts
    74

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    hi, i cant seem to get the connections to work, would like some help please.

    so far i have managed to get the files included and coded:
    Set ftpConn = New Client.
    ftpConn.Connect
    text1.text=ftpConn.IsDataSent

    text1.text displays 'False' and no outgoing connections are made, i have enetered all the other details such as ftp address and port number. Firewall was disabled and so on. No connections are sent out. Do i need to include winsock to get this to work and if so, whats the name for it?

    Please help.

  34. #34

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    hi mathy, I'm not sure if you have the latest version. If not, please download it from the first post.
    In the zip file, there's a vbs script file with sample codes. check that one out. if you still have problems, post it here.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  35. #35
    Lively Member
    Join Date
    Jul 2007
    Posts
    74

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    hi jian, that was a quick reply. I have downloaded the new files from the first script but didnt realise their was a script file. i was trying to look at the ftpClient.vbp for help. Many thanks will have a look a come back to ya if any problems

    Mathy

  36. #36
    Lively Member
    Join Date
    Jul 2007
    Posts
    74

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Hi Jian, all is going good but do have a question! How can i change the length of the timeout code, say to shorten it to 10 seconds?

    Mathy

  37. #37
    New Member
    Join Date
    Jun 2008
    Posts
    3

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Hi Jian, first of all, thank you for the hard work.

    My question (apologies for bothering you, my googling was not up to par):

    I am converting this to .Net, and have gotten pretty much everything worked out (I believe) with the exception of the ws2_32.dll library declarations, namely the as any keywords for some of the variables. And I can't determine what variable types they should be to make the changes. Any advice?

    Thank you.

  38. #38

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    that would be As Object.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  39. #39
    New Member
    Join Date
    Apr 2009
    Posts
    2

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Hi there, I'm trying to integrate this FTP class into my own project, and I keep on getting the error "Expected = " when I try to use the OpenFTP variable. I've done the obvious things like added the class to the project. Here's my code, hopefully someone will be able to point out where I'm going wrong.

    vb Code:
    1. Private Function FTPUpload()
    2.     Dim ftpConn As FTPClass
    3.     Set ftpConn = New FTPClass
    4.    
    5.     With ftpConn
    6.         .OpenFTP("site", "username", "password")
    7.        
    8.     End With
    9. End Function

    Thanks

    Dug

  40. #40
    New Member
    Join Date
    Apr 2009
    Posts
    2

    Re: To all who's doing FTP: Here's an FTP class to simplify things drastically

    Actually forget about that, I seem to have it working now. I'll let you know how I get on with the class

    Cheers

    Dug

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width