-
Feb 25th, 2021, 06:49 AM
#1
Thread Starter
PowerPoster
COPY file from C:\ to ftp dir...
Possible copy a file from c:\ to a dir ftp server
note:
i just have usename and psword of ftp server
-
Feb 25th, 2021, 07:32 AM
#2
Re: COPY file from C:\ to ftp dir...
-
Feb 25th, 2021, 08:47 AM
#3
Addicted Member
Re: COPY file from C:\ to ftp dir...
Take Command Console from jpsoft.com allows you to copy a file from c:\ to a ftp server.
You can download the free TCC Runtime.
From a VB6 program, you can use SHELL to execute tcc runtime, and copy a file from c:\ to a ftp server.
Examples:
Code:
copy ftp://ftp.abc.com/xyz/index index
copy index ftp://ftp.abc.com/xyz/index
Joe
-
Feb 25th, 2021, 10:04 AM
#4
Re: COPY file from C:\ to ftp dir...
Better yet use a modern server that supports secure and firewall-friendly WebDAV.
-
Feb 25th, 2021, 03:43 PM
#5
Thread Starter
PowerPoster
Re: COPY file from C:\ to ftp dir...
experiment....
Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim LocalPath As String
Dim RemotePath As String
LocalPath = "C:\EXPORT_CSV\sinc.csv"
RemotePath = "/public_html/sinc.csv"
With Inet1
.AccessType = icDirect
.Protocol = icFTP
.UserName = "12345"
.Password = "99999"
.RemoteHost = "ftp.nard.it"
.Execute .Url, "PUT " & LocalPath & " " & RemotePath
While .StillExecuting
DoEvents
Wend
.Execute , "CLOSE"
End With
End Sub
the code, go to:
.Execute , "CLOSE"
but i have see via filezilla, the file exists in directori but the lenght of this is 0!!!!!!
-
Feb 25th, 2021, 04:24 PM
#6
Re: COPY file from C:\ to ftp dir...
-
Feb 25th, 2021, 04:56 PM
#7
Thread Starter
PowerPoster
Re: COPY file from C:\ to ftp dir...
Originally Posted by Arnoutdv
Tks for suggestion...
but in:
Code:
..........
Private Sub Command1_Click()
On Error Resume Next
TreeView1.Nodes.Clear
UserRootDirectory = ""
Winsock1.Close: Winsock1.LocalPort = 0
Winsock1.Connect Text4: DoEvents
End Sub
.............
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim i&, NodX As Node, NP$, NotReady As Boolean
On Error Resume Next
Node.Image = "Opened": Node.Expanded = True
NP = Node.Parent.FullPath: If NP = "" Then NP = UserRootDirectory '<<<<<<<<< here error
Do
NotReady = False
For Each NodX In TreeView1.Nodes
If Len(NodX.FullPath) > Len(NP) And Node.Key <> NodX.Key Then
TreeView1.Nodes.Remove NodX.Key: NotReady = True: Exit For
End If
Next NodX
Loop While NotReady
Winsock1.SendData "CWD " & Replace(Node.FullPath, "//", "/") & vbCrLf
ReadCurDir Len(Text1)
End Sub
............
have error 91 - object variable or with. block variable not set
Last edited by luca90; Feb 25th, 2021 at 04:59 PM.
-
Feb 25th, 2021, 05:11 PM
#8
Re: COPY file from C:\ to ftp dir...
There is curl.exe shipped with every Win10 as a built-in utility nowadays.
Btw, Inet control probably does not support *passive* mode.
cheers,
</wqw>
-
Feb 25th, 2021, 09:22 PM
#9
Re: COPY file from C:\ to ftp dir...
Technically, Windows Explorer supports FTP objects.
If you create a shell item with an FTP url, you can drop files on it to upload. This is why my shell browser control can navigate FTP sites and drag/drop from them.
Pretty sure a file copy with IFileOperation would work too.
-
Feb 26th, 2021, 02:41 AM
#10
Re: COPY file from C:\ to ftp dir...
Originally Posted by luca90
Tks for suggestion...
but in:
Code:
..........
Private Sub Command1_Click()
On Error Resume Next
TreeView1.Nodes.Clear
UserRootDirectory = ""
Winsock1.Close: Winsock1.LocalPort = 0
Winsock1.Connect Text4: DoEvents
End Sub
.............
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim i&, NodX As Node, NP$, NotReady As Boolean
On Error Resume Next
Node.Image = "Opened": Node.Expanded = True
NP = Node.Parent.FullPath: If NP = "" Then NP = UserRootDirectory '<<<<<<<<< here error
Do
NotReady = False
For Each NodX In TreeView1.Nodes
If Len(NodX.FullPath) > Len(NP) And Node.Key <> NodX.Key Then
TreeView1.Nodes.Remove NodX.Key: NotReady = True: Exit For
End If
Next NodX
Loop While NotReady
Winsock1.SendData "CWD " & Replace(Node.FullPath, "//", "/") & vbCrLf
ReadCurDir Len(Text1)
End Sub
............
have error 91 - object variable or with. block variable not set
It’s a pity that after being a member for 16 years you don’t even know how to give information.
I have to read the source lines to search for a comment about “error here”
How is the variable declared, when is it set?
Or did you copy a part of the sample code, but not everything what’s needed?
-
Feb 27th, 2021, 01:06 AM
#11
Re: COPY file from C:\ to ftp dir...
So my theory about IFileOperation working seems to be incorrect... kept saying "name invalid or too long" (which wasnt true)
But dragdrop absolutely works, check this out:
Code:
Public Sub UploadToFTP(sFiles() As String)
Dim siFTP As IShellItem
Dim siItems As IShellItemArray
Dim apidl() As Long
Dim cpidl As Long
Dim i As Long
ReDim apidl(UBound(sFiles))
For i = 0 To UBound(apidl)
apidl(i) = ILCreateFromPathW(StrPtr(sFiles(i)))
Next
cpidl = UBound(apidl) + 1
SHCreateShellItemArrayFromIDLists cpidl, VarPtr(apidl(0)), siItems
SHCreateItemFromParsingName StrPtr("ftp://speedtest.tele2.net/upload/"), Nothing, IID_IShellItem, siFTP
If (siItems Is Nothing) Or (siFTP Is Nothing) Then
Debug.Print "Failed"
Exit Sub
End If
Dim dtFTP As IDropTarget
Dim doFiles As IDataObject
siItems.BindToHandler 0&, BHID_DataObject, IID_IDataObject, doFiles
siFTP.BindToHandler 0&, BHID_SFUIObject, IID_IDropTarget, dtFTP
If (dtFTP Is Nothing) Or (doFiles Is Nothing) Then
Debug.Print "no do/dt"
Exit Sub
End If
dtFTP.DragEnter doFiles, 1&, 0&, 0&, DROPEFFECT_COPY
dtFTP.Drop doFiles, 1&, 0&, 0&, DROPEFFECT_COPY
End Sub
You'd format the ftp url ftp://user:pass@ftpsite.com if you needed a username/password, and :port on the end if you need a port besides 21. .com:22
(Requires a reference to oleexp.tlb and the addon module mIID.bas (included in the oleexp zip) for the IID/BHID values)
Other ways are probably more practical, but thought this was a fun alternative.
Last edited by fafalone; Feb 27th, 2021 at 01:14 AM.
-
Mar 1st, 2021, 05:52 PM
#12
Hyperactive Member
Re: COPY file from C:\ to ftp dir...
ftp.exe can also take a script file as a param. Has been in windows since at least windows 2000.
create a file called "commands.txt" and put the ftp commands inside
Code:
open ftp.yoursite.com
user userNameHere
passwordHere
put yourFile.txt
bye
then shell it
Code:
shell("ftp.exe -s:c:\temp\commands.txt", vbnormalmode)
-
Mar 2nd, 2021, 02:01 AM
#13
Re: COPY file from C:\ to ftp dir...
Unfortunately OS provided ftp.exe does not support PASV mode so upload will fail on 90% of public facing ftp servers.
cheers,
</wqw>
-
Mar 2nd, 2021, 10:28 AM
#14
Thread Starter
PowerPoster
Re: COPY file from C:\ to ftp dir...
Originally Posted by fafalone
So my theory about IFileOperation working seems to be incorrect... kept saying "name invalid or too long" (which wasnt true)
But dragdrop absolutely works, check this out:
Code:
Public Sub UploadToFTP(sFiles() As String)
Dim siFTP As IShellItem
Dim siItems As IShellItemArray
Dim apidl() As Long
Dim cpidl As Long
Dim i As Long
ReDim apidl(UBound(sFiles))
For i = 0 To UBound(apidl)
apidl(i) = ILCreateFromPathW(StrPtr(sFiles(i)))
Next
cpidl = UBound(apidl) + 1
SHCreateShellItemArrayFromIDLists cpidl, VarPtr(apidl(0)), siItems
SHCreateItemFromParsingName StrPtr("ftp://speedtest.tele2.net/upload/"), Nothing, IID_IShellItem, siFTP
If (siItems Is Nothing) Or (siFTP Is Nothing) Then
Debug.Print "Failed"
Exit Sub
End If
Dim dtFTP As IDropTarget
Dim doFiles As IDataObject
siItems.BindToHandler 0&, BHID_DataObject, IID_IDataObject, doFiles
siFTP.BindToHandler 0&, BHID_SFUIObject, IID_IDropTarget, dtFTP
If (dtFTP Is Nothing) Or (doFiles Is Nothing) Then
Debug.Print "no do/dt"
Exit Sub
End If
dtFTP.DragEnter doFiles, 1&, 0&, 0&, DROPEFFECT_COPY
dtFTP.Drop doFiles, 1&, 0&, 0&, DROPEFFECT_COPY
End Sub
You'd format the ftp url ftp://user:pass@ftpsite.com if you needed a username/password, and :port on the end if you need a port besides 21. .com:22
(Requires a reference to oleexp.tlb and the addon module mIID.bas (included in the oleexp zip) for the IID/BHID values)
Other ways are probably more practical, but thought this was a fun alternative.
hi bro...
i dont see the path where i can store the file from c:\mydir...
in other case the my parameter are store in a const:
Public Const SERVERFTP = "ftp.my.it"
Public Const USERNAME = "1234"
Public Const PSW = "999999"
Public Const LOCDIR = "C:\mydir"
Public Const FTPDIR = "/public_html/dir1"
Public Const CSVFILE = "sinc.csv"
-
Mar 3rd, 2021, 12:02 PM
#15
Re: COPY file from C:\ to ftp dir...
Originally Posted by wqweto
Unfortunately OS provided ftp.exe does not support PASV mode so upload will fail on 90% of public facing ftp servers.
cheers,
</wqw>
Really? hmm that seems off given that I have been using it to upload files to ftp servers for the last 20 years or so, always worked fine for me.
-
Mar 3rd, 2021, 04:02 PM
#16
Re: COPY file from C:\ to ftp dir...
Originally Posted by DataMiser
Really? hmm that seems off given that I have been using it to upload files to ftp servers for the last 20 years or so, always worked fine for me.
Hint: try ftp.exe pasv mode in google.
Not sure if they upgraded this in Win10 and not sure if PASV mode is used for upload at all or for download only. Certainly ftp.exe is pretty useless impl of the protocol provided that they now include curl.exe in stock OS.
-
Mar 4th, 2021, 04:46 PM
#17
Re: COPY file from C:\ to ftp dir...
Originally Posted by luca90
hi bro...
i dont see the path where i can store the file from c:\mydir...
in other case the my parameter are store in a const:
Public Const SERVERFTP = "ftp.my.it"
Public Const USERNAME = "1234"
Public Const PSW = "999999"
Public Const LOCDIR = "C:\mydir"
Public Const FTPDIR = "/public_html/dir1"
Public Const CSVFILE = "sinc.csv"
You'd call it like this:
Code:
Dim sFile() As String
ReDim sFile(0)
sFile(0) = "C:\mydir\sinc.csv"
UploadToFTP sFile
And modify the UploadToFTP address like ftp://1234:999999@ftp.my.it/public_html/dir1/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|