Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by Joar
at 2024-05-04 23:53:56
Point:500 Replies:20 POST_ID:828496USER_ID:11329
Topic:
Microsoft Visual Basic.Net;;Microsoft Access Database
I have an access app (2007) that needs to upload local files to a web server.
I want to use FTP (or other method if it exists and is better).
This must be done within the vba code!
Later on I will need to download theese files back to the local disc.
How do I do that?
Do I have to save them to a local file before reading them into the app for manipulating?
Normally the files are of type pdf.
I want to use FTP (or other method if it exists and is better).
This must be done within the vba code!
Later on I will need to download theese files back to the local disc.
How do I do that?
Do I have to save them to a local file before reading them into the app for manipulating?
Normally the files are of type pdf.
Expert: Jim Dettman (EE MVE / MS Access MVP) replied at 2024-05-13 05:49:03
<<I did put it in a standard module and then it compiled OK. May be you should have been rewarded for that, but it is to late now.. >>
Not an issue, Als315 was already there. I just added a bit, that's all.
JimD.
Not an issue, Als315 was already there. I just added a bit, that's all.
JimD.
Author: Joar replied at 2024-05-13 05:16:04
JimD:
I did put it in a standard module and then it compiled OK. May be you should have been rewarded for that, but it is to late now..
I did put it in a standard module and then it compiled OK. May be you should have been rewarded for that, but it is to late now..
Expert: Jim Dettman (EE MVE / MS Access MVP) replied at 2024-05-13 03:34:26
I just re-read my comment, which was a bit off; the procedure that addressof specifies cannot be in a class module. That's almost the same thing, but not quite.
JimD.
Author: Joar replied at 2024-05-12 22:44:50
Excellent help! Functions! Sorry for not having awarded the other contributers if I should have done.
Expert: Jim Dettman (EE MVE / MS Access MVP) replied at 2024-05-12 17:43:14
AddressOf is only allowed in a standard code module. It cannot be in a class module (which is what form and report modules are).
JimD.
Author: Joar replied at 2024-05-12 12:41:42
No, all in a form. Why should that do any difference?
Accepted Solution
Expert: als315 replied at 2024-05-12 01:38:44
500 points EXCELLENT
I hope you have included all this text in module, not in a form code?
Author: Joar replied at 2024-05-12 00:26:09
Get the same type of compilation error in that code
(I am using Access 2007 (mdb)
(I am using Access 2007 (mdb)
Expert: als315 replied at 2024-05-11 23:57:55
I've tested last solution (comment 16208871). Accepted is previous.
Author: Joar replied at 2024-05-11 23:33:16
I guess you mean the code in the accepted solution?
I get a compilation error....se the attached image
I get a compilation error....se the attached image
Expert: als315 replied at 2024-05-11 04:42:22
This example is working for me:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21772351.html#16208871
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21772351.html#16208871
Author: Joar replied at 2024-05-11 01:04:17
I am not able to have the FTPGetFile to do the job..and I do not know how to get the excat error from that function.
I have a function that uploads a file using the ftpPutFil.
This functions quite well.
Do you see anything wrong in my ftpGetFile code below?
It is this part of the code that returns false (0):
fOk = FtpGetFileW(hConnect, _
StrPtr(RemoteFile), _
StrPtr(localFile), _
False, _
0, _
FTP_TRANSFER_TYPE_UNKNOWN, 0)
Here is my code:
Private Declare Function FtpGetFileW Lib "wininet.dll" (ByVal hFtpSession As Long, ByVal RemoteFile As String, ByVal LocalPath As String, ByVal FailIfExists As Boolean, ByVal FlagsAndAttributes As Long, ByVal Flags As Long, ByVal Context As Long) As Boolean
Public Function FtpDownLoadFile( _
ByVal server As String, _
ByVal username As String, _
ByVal password As String, _
ByVal RemoteFile As String, _
ByVal localFile As String) As Boolean
Dim fOk As Long
hOpen = InternetOpenW(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0)
hConnect = InternetConnectW(hOpen, _
StrPtr(server), _
INTERNET_DEFAULT_FTP_PORT, _
StrPtr(username), _
StrPtr(password), _
INTERNET_SERVICE_FTP, _
INTERNET_FLAG_PASSIVE, 0)
If hConnect = 0 Then
Debug.Print "InternetConnect failed."; Err.LastDllError
CleanUp
Exit Function
End If
fOk = FtpGetFileW(hConnect, _
StrPtr(RemoteFile), _
StrPtr(localFile), _
False, _
0, _
FTP_TRANSFER_TYPE_UNKNOWN, 0)
CleanUp
FtpDownLoadFile = fOk
End Function
I have a function that uploads a file using the ftpPutFil.
This functions quite well.
Do you see anything wrong in my ftpGetFile code below?
It is this part of the code that returns false (0):
fOk = FtpGetFileW(hConnect, _
StrPtr(RemoteFile), _
StrPtr(localFile), _
False, _
0, _
FTP_TRANSFER_TYPE_UNKNOWN, 0)
Here is my code:
Private Declare Function FtpGetFileW Lib "wininet.dll" (ByVal hFtpSession As Long, ByVal RemoteFile As String, ByVal LocalPath As String, ByVal FailIfExists As Boolean, ByVal FlagsAndAttributes As Long, ByVal Flags As Long, ByVal Context As Long) As Boolean
Public Function FtpDownLoadFile( _
ByVal server As String, _
ByVal username As String, _
ByVal password As String, _
ByVal RemoteFile As String, _
ByVal localFile As String) As Boolean
Dim fOk As Long
hOpen = InternetOpenW(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0)
hConnect = InternetConnectW(hOpen, _
StrPtr(server), _
INTERNET_DEFAULT_FTP_PORT, _
StrPtr(username), _
StrPtr(password), _
INTERNET_SERVICE_FTP, _
INTERNET_FLAG_PASSIVE, 0)
If hConnect = 0 Then
Debug.Print "InternetConnect failed."; Err.LastDllError
CleanUp
Exit Function
End If
fOk = FtpGetFileW(hConnect, _
StrPtr(RemoteFile), _
StrPtr(localFile), _
False, _
0, _
FTP_TRANSFER_TYPE_UNKNOWN, 0)
CleanUp
FtpDownLoadFile = fOk
End Function
Author: Joar replied at 2024-05-10 23:07:07
I will look at the FtpGetFile...
But first I will continu the search for a method for adding the web as a network drive from VBA, because this seemes to give me the simplest solution. Then I may read and save files as with ordinary disc drives. If somebody has a tip on that I will be happy. Comming back....
But first I will continu the search for a method for adding the web as a network drive from VBA, because this seemes to give me the simplest solution. Then I may read and save files as with ordinary disc drives. If somebody has a tip on that I will be happy. Comming back....
Expert: als315 replied at 2024-05-10 12:10:50
I don't know how to add network drive from VBA (it seems simple, but I can't find solution).
For downloading file you can use symmetric function:
Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileW" (ByVal hFtpSession As Long, ByVal RemoteFile As String, ByVal LocalPath As String, ByVal FailIfExists As Boolean, ByVal FlagsAndAttributes As Long, ByVal Flags As Long, ByVal Context As Long) As Boolean
For downloading file you can use symmetric function:
Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileW" (ByVal hFtpSession As Long, ByVal RemoteFile As String, ByVal LocalPath As String, ByVal FailIfExists As Boolean, ByVal FlagsAndAttributes As Long, ByVal Flags As Long, ByVal Context As Long) As Boolean
Author: Joar replied at 2024-05-10 02:56:06
als315 said: You can also connect folder from ftp server as network disk with letter and work with it as with usual network disk
This seemed to be the simplest solution!
I wonder:
Can I do this folder connection from within Access VBA, specifying user name and password?
This way I just have a full access to the ftp server while the access app is uploading files.
This seemed to be the simplest solution!
I wonder:
Can I do this folder connection from within Access VBA, specifying user name and password?
This way I just have a full access to the ftp server while the access app is uploading files.
Author: Joar replied at 2024-05-10 01:08:01
duncanb7:
I have followed your link: http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_26599510.html
and was able to upload a file from my ftp server on the web, but:
1) I am only able to upload to the root level, not to a sub folder.
I cannot see how I can modfy this somewhat cryptical code to do that (se attached code)
2) May I easely change the code to download a file as well?
I have seen there exists a ftpGetfile, but I cannot understand how to use it.
I have followed your link: http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_26599510.html
and was able to upload a file from my ftp server on the web, but:
1) I am only able to upload to the root level, not to a sub folder.
I cannot see how I can modfy this somewhat cryptical code to do that (se attached code)
2) May I easely change the code to download a file as well?
I have seen there exists a ftpGetfile, but I cannot understand how to use it.
Public Function FtpUploadFile( _ ByVal server As String, _ ByVal username As String, _ ByVal password As String, _ ByVal localFile As String, _ ByVal remoteFile As String) As Boolean Dim fOk As Long hOpen = InternetOpenW(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0) hConnect = InternetConnectW(hOpen, _ StrPtr(server), _ INTERNET_DEFAULT_FTP_PORT, _ StrPtr(username), _ StrPtr(password), _ INTERNET_SERVICE_FTP, _ INTERNET_FLAG_PASSIVE, 0) If hConnect = 0 Then Debug.Print "InternetConnect failed."; Err.LastDllError CleanUp Exit Function End If fOk = FtpPutFileW(hConnect, _ StrPtr(localFile), _ StrPtr(remoteFile), _ FTP_TRANSFER_TYPE_UNKNOWN, 0) CleanUp FtpUploadFile = fOkEnd Function 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:
Expert: duncanb7 replied at 2024-05-05 11:28:54
Try this the code is finally working fine in VBA Excell, so similar to Access
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_26599510.html
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_26599510.html
Expert: CodeCruiser replied at 2024-05-05 01:19:09
Expert: als315 replied at 2024-05-05 00:53:03
You can also connect folder from ftp server as network disk with letter and work with it as with usual network disk
Expert: sshah254 replied at 2024-05-05 00:02:13
You can get ActiveX controls for FTP and manipulate them to upload / download files - this is the appropriate way to do it.
You can excecute command line FTP from within VBA using various methods (and command line ftp can be set to use the commands from a script file).
Check this out - http://bytes.com/topic/access/answers/210987-code-controling-ftp-access-vba
Ss
You can excecute command line FTP from within VBA using various methods (and command line ftp can be set to use the commands from a script file).
Check this out - http://bytes.com/topic/access/answers/210987-code-controling-ftp-access-vba
Ss