Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim myStreamWriter As StreamWriter = Nothing
Dim lngWnd As Long = Nothing
Dim strTxtfile As String = Nothing
Dim output2 As String

''''''''''''''''''''''''''''''''''''''''''' looping and Transferring
Dim varSourceAddress As String = "C:\Notification_Pdf"
Dim diaddr As New DirectoryInfo(varSourceAddress)
Dim fiaddr As FileInfo() = diaddr.GetFiles()

While diaddr.GetFiles.Length > 0
    For Each scannedFile As FileInfo In fiaddr
        If scannedFile.Name.Contains("Thumbs") = False Then
            If scannedFile.Exists Then
                output2 = scannedFile.Name
                'output2 = scannedFile.Name.Replace(".docx", ".pdf")

                myStreamWriter = File.CreateText("C:\pdf\Notifications.txt")
                With myStreamWriter
                    .WriteLine("open 196.35.157.148")
                    .WriteLine("securemailftp")
                    .WriteLine("secretmailptf")
                    .WriteLine("lcd C:\Notification_Pdf")
                    .WriteLine("get" & " " & output2)
                    .WriteLine("put" & " " & output2)
                    .WriteLine("byee")
                    .WriteLine("close")
                    .Flush()
                    myStreamWriter.Close()
                End With
                strTxtfile = "C:\pdf\Notifications.txt"
                lngWnd = Shell("ftp -s:" & strTxtfile, vbMinimizedFocus)
                'scannedFile.CopyTo("C:\Notificationss\Archive\" & output2, True)
            End If
        End If
    Next scannedFile
End While
Me.Label1.Text = "Files Transferred"
Posted
Updated 1-Apr-14 4:26am
v2
Comments
Prasad Khandekar 1-Apr-14 10:31am    
Looking at the code myStreamWriter.Close() is redundant and should not be in the with block. For PDF's you should be using binary mode. Just add .WriteLine("binary") statement before .WriteLine("put" & " " & output2).

Regards,
Member 10250527 7-Apr-14 3:27am    
i tried using binary and ascii but the pdf still gets damaged
Prasad Khandekar 8-Apr-14 6:54am    
Have you tried putting all those commands in a batch file and running that from command prompt for one file?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900