Results 1 to 10 of 10

Thread: FTP

  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi
    I've had a few attempts at this today without success.
    The following code transfers files successfully but I need to add a command to check if a folder exists before the files are transferred.
    If it's not, then create one.
    The folder created should represent strRef, so if strRef is 12345 then the path should be "\ConsoleFiles\12345\"
    I think I need to use FileSystemObject but would this need to open a session to the server to check if the folder exists?
    Here's what I have ( no reference to FileSystemObject) in raw format.
    Can anyone help?



    Select Case List1

    Case "123 Leek"
    strRef = InputBox("Please Enter A Leek Job Number", "")
    If strRef = "" Then
    MsgBox "You Must Enter A Leek Job Number Before Proceeding", vbInformation, "Reference Error"
    Exit Sub
    End If

    If Len(strRef) > 5 Then
    MsgBox "Too Many Characters" & vbCrLf & _
    "You Can Only Use 5 Characters" & vbCrLf & _
    "Please Enter A Valid 5 Character Number", vbInformation, "Information": Exit Sub
    End If

    If Len(strRef) < 5 Then
    MsgBox "Not Enough Characters" & vbCrLf & _
    "You Need To Use 5 Characters" & vbCrLf & _
    "Please Enter A Valid 5 Character Number", vbInformation, "Information": Exit Sub
    End If

    For N = 0 To List2.ListCount - 1


    FTPSource = "L:\Mmpdf\ConsoleFiles\" & Left(List2.List(N), 5) & "\"
    FTPPath = "\ConsoleFiles\"
    FF = Right(List2.List(N), 7)



    frmFTP1024.FTPFile "SERVER", "PUT", "USER", "PASSWORD", FTPSource & List2.List(N), FTPPath & strRef & FF
    Next N

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Hi Dave,

    The Scripting.FileSystemObject object has a FolderExists method, but you'd have to connect to the target server to do that. I can't help you with that.

    For what it's worth, here is the syntax (in VB6 / VBA style):

    Code:
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FolderExists("\\serverpath\ConsoleFiles\" & strRef) Then
      ...
    Else
      ...
    End If

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans

    Does this help, I tried the fso statement in the "PUT" section as I think this opens the connection.
    It crashed because strRef isn't created until later in the code?

    Friend Sub FTPFile(ByVal sFTPServer As String, _
    ByVal sFTPCommand As String, _
    ByVal sFTPUser As String, _
    ByVal sFTPPwd As String, _
    ByVal sFTPSrcFileName As String, _
    ByVal sFTPTgtFileName As String)

    Dim oFS As Scripting.FileSystemObject
    Dim sURL As String

    On Error GoTo FTPFileExit

    Me.HRG True
    msCurrentFile = ""

    Set oFS = New Scripting.FileSystemObject

    sURL = "ftp://" & sFTPUser & ":" & sFTPPwd & "@" & sFTPServer

    Inet1.Protocol = icFTP
    Inet1.RequestTimeout = 60
    Inet1.RemotePort = 21
    Inet1.AccessType = icDirect
    Inet1.URL = sURL

    Select Case sFTPCommand

    Case "PUT"

    msCurrentFile = sFTPSrcFileName
    If oFS.FileExists(sFTPSrcFileName) = False Then GoTo FTPFileExit
    Inet1.Execute sURL, sFTPCommand & Space(1) & sFTPSrcFileName & " " & sFTPTgtFileName

    Case "GET"

    msCurrentFile = sFTPTgtFileName
    If oFS.FileExists(sFTPTgtFileName) = True Then oFS.DeleteFile sFTPTgtFileName, True
    Inet1.Execute sURL, sFTPCommand & Space(1) & sFTPSrcFileName & " " & sFTPTgtFileName

    End Select

    Me.WaitForResponse
    Inet1.Execute sURL, "quit"
    Me.WaitForResponse

    FTPFileExit:
    Set oFS = Nothing
    HRG False
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I don't think you can use FileSystemObject to check a file or folder on the target location.

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Seems you're right !

    I tried:

    Case "PUT"

    msCurrentFile = sFTPSrcFileName
    If oFS.FileExists(sFTPSrcFileName) = False Then GoTo FTPFileExit
    If oFS.FileExists(sFTPTgtFileName, vbDirectory) = False Then MkDir sFTPTgtFileName
    Inet1.Execute sURL, sFTPCommand & Space(1) & sFTPSrcFileName & " " & sFTPTgtFileName

    Which doesn't work

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I'm not sure it's possible at all, but perhaps someone else will have a suggestion...

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    I fired up an FTP program, navigated to a folder, then made a new directory. The FTP client sent DIR to obtain the list of existing files/folders, then sent MKD to make the new directory. If you can find documentation on these commands for your server, I think that would help. I'm most curious what format the DIR information is in. (I turned on WireShark to see for myself, but because I'm using FTP over SSH, it was encrypted...)

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have taken a different approach to this.
    Instead of creating a folder via FTP I have changed the load up script to create it instead.
    Each time the user loads the software it checks to see if "L:\MMPDF\Transfer\" exists, if not then create it.
    The transfer sequence of the individual files is good and works perfectly.

    I now need to count the number of files in that folder that begin with a specific number ( dependant what file the user is looking at).
    With the following code, a file count is successful, but it counts all files and not just files that begin with strLeft5.
    Where do I put strLeft5 to count only files it refers to?

    Many thanks for the help.

    Dim fso As New Scripting.FileSystemObject
    Dim fld As Scripting.Folder
    Dim strPath As String
    Dim strTrans5 As String


    strPath = "L:\mmpdf\Transfer\"
    strTrans5 = Left(Me.txtEst, 5)

    If fso.FolderExists(strPath) Then
    Set fld = fso.GetFolder(strPath)
    If fld.Files.Count > 0 Then
    Me.txtTrans.Text = fld.Files.Count

    End If
    End If
    Set fld = Nothing
    Set fso = Nothing

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Don't you mean strTrans5 instead of strLeft5? Anyway, you'll have to loop through the files to count those whose name starts with the specified text:

    Code:
      Dim fso As New Scripting.FileSystemObject
      Dim fld As Scripting.Folder
      Dim fil As Scripting.File
      Dim strPath As String
      Dim strTrans5 As String
      Dim lngCount As Long
     
      strPath = "L:\mmpdf\Transfer\"
      strTrans5 = Left(Me.txtEst, 5)
       
      If fso.FolderExists(strPath) Then
        Set fld = fso.GetFolder(strPath)
        lngCount = 0
        For Each fil In fld.Files
          If fil.Name Like strLeft5 & "*" Then ' or strTrans5 ?
            lngCount = lngCount + 1
          End If
        Next fil
        If lngCount > 0 Then
          Me.txtTrans.Text = lngCount
        End If
      End If
      Set fil = Nothing
      Set fld = Nothing
      Set fso = Nothing

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've been trying to do this for ages.

    Cheers Hans

    Works great )

Posting Permissions

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