-
How can i make vb upload a file to my web server?
Hi guys,
Is it possible and if so how do i go about doing it.
To make it so when a user presses a command button it will upload the file 'favorites.txt' (which is located in the app directory) to my webserver?
So the user presses command1 then it uploads the file to my web server like www.mywebsite.com/files/
Thanks,
Jamie
-
Re: How can i make vb upload a file to my web server?
Look at the Internet transfer control (aka INet).
-
Re: How can i make vb upload a file to my web server?
i use FtpPutFile API to do it,instead of ocx.
if you have any questions about the ftp api ,just google it
the below lists the ftp apis may be used.
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Long, ByVal sServerName As String, _
ByVal nServerPort As Integer, ByVal sUsername As String, _
ByVal sPassword As String, ByVal lService As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Public Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" _
(ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Public Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _
(ByVal hFtpSession As Long, ByVal lpszExsiting As String, ByVal lpszNew As String) As Boolean
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
-
Re: How can i make vb upload a file to my web server?
Try this works for me:
With Inet1
.URL = "ftp://Yoursite.com"
.UserName = "YourUserName"
.Password = "YourPassword"
.Execute , "PUT C:\YourFile.txt /YourText.txt"
End With
-
Re: How can i make vb upload a file to my web server?
Hi guys, Hope some one can help me here.
The code by mickeykelely works amazingly well. How ever it dont upload to a folder on my web server if it has a space.
For example if i have the folder 'Games and music' it wont upload to it...
BUT if i have the folder like this Gamesandmusic' it will upload the file..
Does anyone know how i can make it so it uploads with spaces in the folder names...
also how do i get this to work?
.Execute , "PUT text1.text /YourText.txt" (It dont do the text1.text)
Thanks
Jamie
-
Re: How can i make vb upload a file to my web server?
also how do i get this to work?
.Execute , "PUT text1.text /YourText.txt" (It dont do the text1.text)
Tou can't PUT data in Text1.Text. It must be a file.
Try something like this:
Code:
Private Sub Command1_Click()
Dim LocalPath As String
Dim RemotePath As String
LocalPath = Chr(34) & App.Path & "\Text1Data.txt" & Chr(34)
'
' If you want to put the file in the root directory then just use filename only
'
RemotePath = Chr(34) & "path to directory/filename" & Chr(34)
With Inet1
.AccessType = icDirect
.Protocol = icFTP
.UserName = "your username"
.Password = "your password"
.RemoteHost = "www.sitename.com" '<--- You may have to use ftp.sitename.com"
.Execute .URL, "PUT " & LocalPath & " " & RemotePath
While .StillExecuting
DoEvents
Wend
.Execute , "CLOSE"
End With
MsgBox "Transfer Complete"
End Sub
-
Re: How can i make vb upload a file to my web server?
Quote:
Originally Posted by
JamieWarren09
For example if i have the folder 'Games and music' it wont upload to it...
BUT if i have the folder like this Gamesandmusic' it will upload the file..
That is because INet control does not support spaces in folder/file names - it truncates text after the first space.
-
Re: How can i make vb upload a file to my web server?
Perhaps something like:
Code:
.Execute , "PUT ""D:\Games and Music\fuddly.txt"" fuddly.txt"
-
Re: How can i make vb upload a file to my web server?
That is because INet control does not support spaces in folder/file names
Not if within quote marks. See post 6
-
Re: How can i make vb upload a file to my web server?
From what I recall spaces were not supported even if you use quotes, brackets, etc. Haven't done it in awhile though.
-
Re: How can i make vb upload a file to my web server?
Hui,
Thanks for the replys. How ever is there Nyeay or another way I can upload to folders with spaces. It's just I have over 600 folders on my web server and I can't sit and rename everyone to remove the spaces..
Thanks jamie
-
Re: How can i make vb upload a file to my web server?
you can try using a shell object, i find it is much easier to work with than the inet control, can handle paths and filenames with spaces, can copy entire folders, with sub folders
there are some examples in this forum, search on shell ftp,
note files are copied asyncronously, so the code will continue without waiting for the files to finish copying
-
Re: How can i make vb upload a file to my web server?
Hi Westconn, THanks for the reply.
I found this code
dim initdir as variant
initdir = "ftp://user:[email protected]/myfolder"
Set sh = CreateObject("shell.application")
Set n = sh.namespace(initdir)
n.copyhere filepath\name ' can be file or folder
which i think was provided by yourself in another post. How ever I am getting a error on this line..
n.copyhere filepath\name ' can be file or folder
I changed it to - n.copyhere C:\old\main\songs.son ' can be file or folder
But it gives me compile error:
Syntax error
Any ideas how to correctly put in the file path?
Thanks Jamie
-
Re: How can i make vb upload a file to my web server?
string needs to be enclosed in quotes
vb Code:
n.copyhere "C:\old\main\songs.son" ' can be file or folder
note if you use variable to pass filenames, must be of type variant
-
Re: How can i make vb upload a file to my web server?
Hi Mate
I tried that, it gives me the error
Object variable or with block not set
Thanks
Jamie
-
Re: How can i make vb upload a file to my web server?
If you run this:
Code:
'
'
Dim initdir As Variant
initdir = "ftp://<--user-->:<--password-->@www.myserver.com.au/myfolder"
Set sh = CreateObject("shell.application")
Set n = sh.namespace(initdir)
n.copyhere "C:\old\main\songs.son" ' can be file or folder
'
'
I guarantee you it works. I know because I just ran it and it uploaded the file to my website.
If you simply just can't get it to work then the one I posted in #6 works just as well.
If you have problems then you are doing something wrong or it's your website or something else.
-
Re: How can i make vb upload a file to my web server?
Still not working, Is there any other way of uploading a file by ftp to folders with spaces?
Thanks
Jamie
-
Re: How can i make vb upload a file to my web server?
Still not working
That is not the way to get help. You need to work with us and tell us why it isn't working; where it isn't working and show the relavent code for support. No one here is going to be able to help you if you don't do this.
I get the impression that you are not reading these posts. I know that #6 and #16 work for sure.
The code works; you are just setting it up wrong
Yes, there are other ways. Look at post #3. You can also use pure FTP; you can use Winsock, you can ShellExecute ftp.exe, and there are a few APIs that will do it.
-
Re: How can i make vb upload a file to my web server?
It's the same error :
Object variable or with block not set
Thanks
Jamie
Highlights the n.copyhere "C:\old\main\songs.son" ' can be file or folder line
thanks
Jamie.
-
Re: How can i make vb upload a file to my web server?
Post your code; not a type written copy of it. That statement works for me so your problem lies elsewhere. As a matter of fact. If your arguments are incorrect you will not receive any errors at all; it just wont do anything.
-
Re: How can i make vb upload a file to my web server?
the error indicates you are not logged into the ftp server or your path (initdir) contains a folder that does not exist on your server, eg myfolder is invalid or your username or password are incorrect, we can not fix those for you, nor can we provide examples specific to your ftp server
if you want someone to test for you we would need to be able to login to your ftp server, with user name and password, which you may not want to post here, but you could pm to someone to help you
you can test before the error
vb Code:
if n is nothing then msgbox "unable to login or folder invalid"
-
Re: How can i make vb upload a file to my web server?
Hey Guys, The error has now gone!
However,
Using the code above and with the right details, Nothing is happening now, it's not uploading anything to the server.. What is the cause of this?
Cheers
jamie
-
Re: How can i make vb upload a file to my web server?
it does come up with the window saying calculating how long e.t.c
-
Re: How can i make vb upload a file to my web server?
Maybe somebody hijacked your account and changed the password. FTP is great that way, sending your logon credentials in plain text.
-
Re: How can i make vb upload a file to my web server?
No ones changed any of my details, besides i've just made another ftp account, same thing (no error message) but dont upload!
-
Re: How can i make vb upload a file to my web server?
Uploading a file to a remote computer doesn't take rocket science. It's just as easy as copying a file from one directory to another on your own computer.
Here's your problem(s).
1) Your local path is incorrect
2) Your remote path is incorrect
3) Your username and/or password is incorrect
4) Your ftp server doesn't allow data transfer
5) Your initdir is incorrect
6) Your computer has a firewall preventing I/O
Either any one of the above or all of them
Good luck.
-
Re: How can i make vb upload a file to my web server?
How am i not listening to you. if i hadent been listening to you, the error message would have not gone.
Your saying if my arguments are incorrect nothing would happen, Yet westconn1 is saying that the error i got was cause the details to my server was incorrect.. My details are fine...
I'm sorry if it seems i am not doing what you are saying.. But I am.
-
Re: How can i make vb upload a file to my web server?
Your saying if my arguments are incorrect nothing would happen, Yet westconn1 is saying that the error i got was cause the details to my server was incorrect.. My details are fine...
If your parameters are incorrect you will not get any errors from the shell.application side. Any errors you get are from VB because of syntax or run-time. If you run the code exactly as is you will not get any errors at all unles the error is caused from somewhere else in your code but it has nothing to do with your uploading a file.
This is one of the simpliest ways to upload or download files from ftp sites.
Now you say you are not getting any errors but nothing is being uploaded. You know this to be true because you used an FTP client to go to your FTP site and you are looking in the correct folder and did not see your files there? Only answer to this is one of your parameters are still incorrect or your ftp server is blocking the data transfer or you have a firewall blocking transfer. One thing for sure is that the code given to you is absolutely correct.
If you can't get it to work either try some other approach or do as westconn suggested in his post #21. PM someone with you user name and password and allow that person to test for you using your ftp server and your project.
-
Re: How can i make vb upload a file to my web server?
I have a question , I was wondering if you could help me ...
I want to make a program which uploads a text file to the server with
internet control (with Username and Pass)
I need the following features:
-The file which is being uploaded is in a specific drive
-I have a text box with specific text in it which i want it to be the
name of uploaded file
The problem with the code you posted is that i can not change the name of file ( /YourText.txt)
to the text in textbox
-
Re: How can i make vb upload a file to my web server?
this is an old thread, you should have started your own new thread
you should tell us what code you are trying to use, ftp upload to server, and which line is the problem
possibly try like
Code:
.Execute , "PUT C:\" & textbox.text & " /" & textbox.text , change c: to your drive and the name of the textbox to suit
-
Re: How can i make vb upload a file to my web server?
Quote:
Originally Posted by
westconn1
this is an old thread, you should have started your own new thread
you should tell us what code you are trying to use, ftp upload to server, and which line is the problem
possibly try like
Code:
.Execute , "PUT C:\" & textbox.text & " /" & textbox.text , change c: to your drive and the name of the textbox to suit
Thanks for your guidance on posting new thread ...
I know how to work with :
Code:
.Execute , "PUT C:\YourFile.txt /YourText.txt"
The problem is that when the code is in "" , I can not use text in the textbox as uploaded file's name . Because the name will be TEXT1.TEXT! not the text in the textbox
Thanks for you respond
-
Re: How can i make vb upload a file to my web server?
did you test what i suggested?
the content of the textbox would be in the string, for both sourcefilename and destinationfilename
to see what the string actually contains, try
Code:
msgbox "PUT C:\" & textbox.text & " /" & textbox.text
assuming you changed the name of the textbox to match the one you are using
if your filenames can contain spaces, you will may have issues using inet control
-
Re: How can i make vb upload a file to my web server?
Thanks for your help , It works!
Of course Just one of the Textbox.text is enough when the directory is specific , like this :
.Execute , "PUT C:\YourFile.txt" & " /" & Text1.Text
Text1.text = The name of file not the name of file in drive!
:)
-
Re: How can i make vb upload a file to my web server?
There is something Strange !
When The Directory is for example " PUT C:\Text1.txt" , It works! But when the directory is a little bit longer , it does not work!
What is the reason of this ?
Thanks a million ...
-
Re: How can i make vb upload a file to my web server?
The path length does have a limit
What is the little bit longer path?
-
Re: How can i make vb upload a file to my web server?
Quote:
The name of file not the name of file in drive!
this makes so much sense
Quote:
But when the directory is a little bit longer
does the longer path contain spaces?
-
Re: How can i make vb upload a file to my web server?
Something like this:
C:\Program Files\New Folder\1.txt
I do not think that it is that long !:D
-
Re: How can i make vb upload a file to my web server?
program files and new folder contain spaces
i am not sure if inet can work with paths with spaces, at the very least the path would have to be enclosed in " " s
there is a disclaimer to the effect that inet can not work with spaces near the beginning of this thread, but i have not tested
you could try to convert the long folder /filenames to their short path equivalent
-
Re: How can i make vb upload a file to my web server?
Anyway , thanks for your respond . If i find a way to solve this , I will let you know for sure :)
-
Re: How can i make vb upload a file to my web server?
EDIT: I added the filename to the end of the RemotePath string. It did upload the file, but I still got state 11 = Error communicating. And, the file is empty
I know I'm way late, but here I am...
I get a serires of "States" from the iNet control. It seems like my computer and my website are talking fine, but then I get state 11 = "An error occurred in communicating with the host computer."
My FTP software shows my path as "anadrac.com/fivecrowns". I've also tried "/anadrac.com/fivecrowns" and "anadrac.com/fivecrowns/"
Like jmsrickland said, I must have something wrong.
Thanks for any help,
Joe
Code:
Dim LocalPath As String
Dim RemotePath As String
LocalPath = Chr(34) & App.Path & "\fcGameData.txt" & Chr(34)
'
' If you want to put the file in the root directory then just use filename only
'
RemotePath = Chr(34) & "anadrac.com/fivecrowns" & Chr(34)
With Inet1
.AccessType = icDirect
.Protocol = icFTP
.URL = "ftp://anadrac.com"
.UserName = "username"
.Password = "password"
.RemoteHost = "ftp.anadrac.com" '<--- You may have to use ftp.sitename.com"
.Execute .URL, "PUT " & LocalPath & " " & RemotePath
While .StillExecuting
DoEvents
Wend
.Execute , "CLOSE"
End With