473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Posting to a website

489 256MB
In my application I can create PDF's from any reports. I would like to be able to post those PDF's directly to my website, Question is there a way to do this directly from the program.
Thanks for the help I always can find answers here.
Jan 12 '14 #1
13 1759
zmbd
5,501 Expert Mod 4TB
Really not enough information; thus, the answer is maybe.

It depends on how you are uploading the files.
Jan 12 '14 #2
CD Tom
489 256MB
Right now I am using ipswitch WS-FTP I connect to the website and then upload the PDF file. If possible I would like to make this an option in the program so a user could put his web address user name and password into a file where I could let the VB program use it to connect to the given website and upload the file automatically.
I hope this is a little more of what you need.
Thanks
Jan 12 '14 #3
zmbd
5,501 Expert Mod 4TB
You didn't mention which version of Access.

There are some code snippettes about useing FTP out there on the net that might prove usefull to you; however, nothing native that I'm aware of at this time.

I'll dig a little bit deeper, there may be something in the publishing routines, in ACC2010 they're for sharepoint now; however, who knows?
Jan 13 '14 #4
CD Tom
489 256MB
Thanks, I'm using Access 2007 right now. I'll look around on the web and see what I can find. If I find anything I'll post it.
Jan 13 '14 #5
CD Tom
489 256MB
I found something on the web that seems like what I was looking for. I've put that information into my program but can't get it to work. I keep getting the message internet failed. The link to the program is http://www.tek-tips.com/faqs.cfm?fid=5904 I don't understand some of this code. Don't know if you can help but thought I'd ask.
Thanks for any help
Jan 13 '14 #6
zmbd
5,501 Expert Mod 4TB
I suggest you start out here as this will help you catch the most common things: > Before Posting (VBA or SQL) Code

If that doesn't work, then insert what you have here... the reason I ask that is because there maybe typos or other goodies the Gremlins inserted for you while you typed. (I see them do that to me often - You know I'm a perfect typest so it as to be the Gremlins, right? };-D ).

Please remember to Format your code with the [CODE/] button
Jan 13 '14 #7
CD Tom
489 256MB
Ok I can do that. However I did just copy and paste the code into the system. I did a compile and everything was ok. Anyway here's all the code
Modules:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. ' Set Constants
  5. Const FTP_TRANSFER_TYPE_ASCII = &H1
  6. Const FTP_TRANSFER_TYPE_BINARY = &H2
  7. Const INTERNET_DEFAULT_FTP_PORT = 21
  8. Const INTERNET_SERVICE_FTP = 1
  9. Const INTERNET_FLAG_PASSIVE = &H8000000
  10. Const GENERIC_WRITE = &H40000000
  11. Const BUFFER_SIZE = 100
  12. Const PassiveConnection As Boolean = True
  13.  
  14. ' Declare wininet.dll API Functions
  15. Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
  16.     (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
  17.  
  18. Public Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" _
  19.    (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Boolean
  20.  
  21. Public Declare Function InternetWriteFile Lib "wininet.dll" _
  22. (ByVal hFile As Long, ByRef sBuffer As Byte, ByVal lNumBytesToWite As Long, _
  23. dwNumberOfBytesWritten As Long) As Integer
  24.  
  25. Public Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" _
  26. (ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long, ByVal Flags As Long, ByVal Context As Long) As Long
  27.  
  28. Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
  29. (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
  30.       ByVal lpszRemoteFile As String, _
  31.       ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
  32.  
  33. Public Declare Function FtpDeleteFile Lib "wininet.dll" _
  34.     Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
  35.     ByVal lpszFileName As String) As Boolean
  36. Public Declare Function InternetCloseHandle Lib "wininet.dll" _
  37. (ByVal hInet As Long) As Long
  38.  
  39. Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
  40. (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
  41. ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
  42.  
  43. Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
  44. (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, _
  45. ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, _
  46. ByVal lFlags As Long, ByVal lContext As Long) As Long
  47.  
  48.  
  49. Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
  50. (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
  51.       ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, _
  52.       ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
  53.  
  54. Declare Function InternetGetLastResponseInfo Lib "wininet.dll" _
  55.       Alias "InternetGetLastResponseInfoA" _
  56.        (ByRef lpdwError As Long, _
  57.        ByVal lpszErrorBuffer As String, _
  58.        ByRef lpdwErrorBufferLength As Long) As Boolean
  59.  
  60. Function FTPFile(ByVal HostName As String, _
  61.     ByVal UserName As String, _
  62.     ByVal Password As String, _
  63.     ByVal LocalFileName As String, _
  64.     ByVal RemoteFileName As String, _
  65.     ByVal sDir As String, _
  66.     ByVal sMode As String) As Boolean
  67.  
  68.     On Error GoTo Err_Function
  69.  
  70. ' Declare variables
  71. Dim hConnection, hOpen, hFile  As Long ' Used For Handles
  72. Dim iSize As Long ' Size of file for upload
  73. Dim Retval As Variant ' Used for progress meter
  74. Dim iWritten As Long ' Used by InternetWriteFile to report bytes uploaded
  75. Dim iLoop As Long ' Loop for uploading chuncks
  76. Dim iFile As Integer ' Used for Local file handle
  77. Dim FileData(BUFFER_SIZE - 1) As Byte ' buffer array of BUFFER_SIZE (100) elements 0 to 99
  78.  
  79. ' Open Internet Connecion
  80. hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)
  81.  
  82. ' Connect to FTP
  83. hConnection = InternetConnect(hOpen, HostName, INTERNET_DEFAULT_FTP_PORT, UserName, Password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
  84.  
  85. ' Change Directory
  86. Call FtpSetCurrentDirectory(hConnection, sDir)
  87.  
  88. ' Open Remote File
  89. hFile = FtpOpenFile(hConnection, RemoteFileName, GENERIC_WRITE, IIf(sMode = "Binary", FTP_TRANSFER_TYPE_BINARY, FTP_TRANSFER_TYPE_ASCII), 0)
  90.  
  91. ' Check for successfull file handle
  92. If hFile = 0 Then
  93.     MsgBox "Internet - Failed!"
  94.     ShowError
  95.     FTPFile = False
  96.     GoTo Exit_Function
  97. End If
  98.  
  99. ' Set Upload Flag to True
  100. FTPFile = True
  101.  
  102. ' Get next file handle number
  103. iFile = FreeFile
  104.  
  105. ' Open local file
  106. Open LocalFileName For Binary Access Read As iFile
  107.  
  108. ' Set file size
  109. iSize = LOF(iFile)
  110.  
  111. ' Iinitialise progress meter
  112. Retval = SysCmd(acSysCmdInitMeter, "Uploading File (" & RemoteFileName & ")", iSize / 1000)
  113.  
  114. ' Loop file size
  115. For iLoop = 1 To iSize \ BUFFER_SIZE
  116.  
  117.     ' Update progress meter
  118.     Retval = SysCmd(acSysCmdUpdateMeter, (BUFFER_SIZE * iLoop) / 1000)
  119.  
  120.     'Get file data
  121.     Get iFile, , FileData
  122.  
  123.     ' Write chunk to FTP checking for success
  124.     If InternetWriteFile(hFile, FileData(0), BUFFER_SIZE, iWritten) = 0 Then
  125.         MsgBox "Upload - Failed!"
  126.         ShowError
  127.         FTPFile = False
  128.        GoTo Exit_Function
  129.     Else
  130.         ' Check buffer was written
  131.         If iWritten <> BUFFER_SIZE Then
  132.             MsgBox "Upload - Failed!"
  133.             ShowError
  134.             FTPFile = False
  135.             GoTo Exit_Function
  136.         End If
  137.     End If
  138.  
  139. Next iLoop
  140.  
  141. ' Handle remainder using MOD
  142.  
  143.     ' Update progress meter
  144.     Retval = SysCmd(acSysCmdUpdateMeter, iSize / 1000)
  145.  
  146.     ' Get file data
  147.     Get iFile, , FileData
  148.  
  149.     ' Write remainder to FTP checking for success
  150.     If InternetWriteFile(hFile, FileData(0), iSize Mod BUFFER_SIZE, iWritten) = 0 Then
  151.         MsgBox "Upload - Failed!"
  152.         ShowError
  153.         FTPFile = False
  154.         GoTo Exit_Function
  155.     Else
  156.         ' Check buffer was written
  157.         If iWritten <> iSize Mod BUFFER_SIZE Then
  158.             MsgBox "Upload - Failed!"
  159.             ShowError
  160.             FTPFile = False
  161.             GoTo Exit_Function
  162.         End If
  163.     End If
  164.  
  165. Exit_Function:
  166.  
  167. ' remove progress meter
  168. Retval = SysCmd(acSysCmdRemoveMeter)
  169.  
  170. 'close remote file
  171. Call InternetCloseHandle(hFile)
  172.  
  173. 'close local file
  174. Close iFile
  175.  
  176. ' Close Internet Connection
  177. Call InternetCloseHandle(hOpen)
  178. Call InternetCloseHandle(hConnection)
  179.  
  180. Exit Function
  181.  
  182. Err_Function:
  183. MsgBox "Error in FTPFile : " & Err.Description
  184. GoTo Exit_Function
  185.  
  186. End Function
  187.  
  188. Sub ShowError()
  189.    Dim lErr As Long, sErr As String, lenBuf As Long
  190.    'get the required buffer size
  191.    InternetGetLastResponseInfo lErr, sErr, lenBuf
  192.    'create a buffer
  193.    sErr = String(lenBuf, 0)
  194.    'retrieve the last respons info
  195.    InternetGetLastResponseInfo lErr, sErr, lenBuf
  196.    'show the last response info
  197.    MsgBox "Last Server Response : " + sErr, vbOKOnly + vbCritical
  198. End Sub
  199.  
Code behind the form.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Upload_Click()
  2.  
  3. On Error GoTo Err_Upload_Click
  4.  
  5. ' Check for Selected file
  6. If Nz(Me!FileName, "") = "" Then
  7.     MsgBox "Please select file to upload first!"
  8.     Exit Sub
  9. End If
  10.  
  11. ' Check for FTP Server
  12. If Nz(Me!FTPDomain, "") = "" Then
  13.     MsgBox "Please enter FTP Domain!"
  14.     Exit Sub
  15. End If
  16.  
  17. ' Check for UserName
  18. If Nz(Me!UserName, "") = "" Then
  19.     MsgBox "Please enter User Name!"
  20.     Exit Sub
  21. End If
  22.  
  23. ' Check for Password
  24. If Nz(Me!FTPPWord, "") = "" Then
  25.     MsgBox "Please enter Password!"
  26.     Exit Sub
  27. End If
  28.  
  29. ' Set Default upload directory to root if nothing supplied
  30. If Nz(Me!ServerDir, "") = "" Then
  31.     Me!ServerDir = "/"
  32.     Me.Refresh
  33. End If
  34.  
  35. ' Upload file
  36. If FTPFile(Me!FTPDomain, Me!UserName, Me!FTPPWord, Me!FileName, Me!ShortName, Me!ServerDir, Me!Mode) Then
  37.     MsgBox "Upload - Complete!"
  38. End If
  39.  
  40. Exit_Upload_Click:
  41.     Exit Sub
  42.  
  43. Err_Upload_Click:
  44.     MsgBox "Error in Upload_Click : " & Err.Description
  45.     Resume Exit_Upload_Click
  46.  
  47. End Sub
  48.  
I'm not sure how this is supposed to connect to the internet, I noticed the use of the wininet.dll. Wish I knew more about this. Thanks for your help again.
Jan 14 '14 #8
zmbd
5,501 Expert Mod 4TB
Sorry, I should have asked you for the exact error and for the method/code you are using to call the procedure.

Have you tried stepping thru the code?
Jan 14 '14 #9
CD Tom
489 256MB
OK, I fillin the form an select the Click to upload it calls the FTPFile with all the information. When it gets to the 'Open Internet Connection the hOpen shows 13369348 the next step 'connect to FTP the hConnection shows a 0, the next step 'Open Remote File the hFile shows a 0, the 'check for successful file handle is where the error shows up.
I would send you the website I'm trying to connect to but don't want to give out the password. I hope you understand.

Thanks
Jan 14 '14 #10
NeoPa
32,556 Expert Mod 16PB
Silly question Tom, but have you checked that you can access your FTP site manually (using any other software) at around the same time you run any of your tests?

If not, it's worth excluding that possibility from the mix.
Jan 14 '14 #11
CD Tom
489 256MB
Yes I normally use ipswitch to connect and have no problem. In the form it shows FTP Domain(ftp.domain.com) I've tried that way and ftp:// and still get the same error.
Jan 14 '14 #12
CD Tom
489 256MB
Ok, after I logged onto the Powweb.com website and checked my ftp site I found that I was using the wrong ftp domain name. I changed it to the correct one and everything worked fine. I guess if I knew what I was doing I would have looked at that sooner. Thanks for all you expert help.
Jan 14 '14 #13
NeoPa
32,556 Expert Mod 16PB
Often, when looking at code and all seems fine except it doesn't work, the answer lies elsewhere. A nudge is often all that's required to get you looking at other possible reasons. You did a good job finding that.
Jan 14 '14 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alice | last post by:
Hi all How can i change the status bar icon for my website Or The icon shown in user's Task Manager for the browser process fetching my website Thanks in Advance Alic
2
by: Tim::.. | last post by:
Can someone please tell me how I release an asp.net website using VS 2003... Do I have to go through the whole site and change the links for the picutes using find and replace of is there an...
7
by: Jonathan Wood | last post by:
Greetings, I have extensive programming experience (nearly 20 years) but have yet to write a full-blown Web application. In fact, I have done hardly any server/client/database programming at...
5
by: NoNickname | last post by:
Basically, how do I know that the release versions of all components are being published? The Build | Configuration Manager is confusing me a little in VS2005. I have three projects in my...
7
by: AmitKu | last post by:
I am trying to do a URL post using HttpWebRequest, but it fails because I am hosting on Network Solutions, and their servers are all medium trust. Apparently HttpWebRequest doesn't work on medium...
1
by: =?Utf-8?B?SnVkeSBMYXU=?= | last post by:
Hi all, Does anyone have any 2.0 .NET + AJAX web U.I. suggestion for status posting website? My application involves displaying status of a running task. Client brower will query server for...
4
by: Boki | last post by:
Hi All, I need to let user type some text in a textbox, and user will click a button to submit the material. It is very straightforward if we implement it by single thread. But the...
3
by: =?Utf-8?B?SGVyYg==?= | last post by:
Can I use the Website Administration tool to manage users and roles for multiple ASP.NET applications using a single, common ASPNETDB? If so, what changes do I have to make to the web.config...
3
by: =?Utf-8?B?SGVyYg==?= | last post by:
I've developed an ASP.NET website that runs fine on my local WinXP IIS and on my server's IIS, both are IIS6.0 The site uses a master page that has the following declaration: <%@ Master...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.