Does anyone know if its possible to make a ftp-file transfer by vba?
What I have in mind is a routine in vba or a macro wich will e.g. transfer my database or parts of it to a back-up site
25 5993 NeoPa 32,563
Recognized Expert Moderator MVP
I just finished implementing one this last week in fact :)
It's not too simple but is certainly possible. Let me dig up some details.
NeoPa 32,563
Recognized Expert Moderator MVP
I start off with two named ranges in a hidden sheet of my workbook. Carats (^) indicate that the following character should indicate a replacement string.
^A = Account name on FTP site
^C = A placeholder to add an optional cd line in FTP file if required - If not set to empty line
^F = Name of file required to upload
^N = Name of FTP file (excluding the .Ftp bit) - Use this for CMD file too for simplicity
^P = Password for ^A
^R = Root Folder - the folder that the spreadsheet is found in
^S = FTP site address
The data for the files themselves are included below. I needed a fair amount of flexibility. If you don't then you can replace the variable bits with hard coded items. Range("CMD") - ECHO ON
-
CD /D "^R"
-
"%SystemRoot%\System32\FTP.Exe" -n -s:^N.Ftp -w:16384 ^S
Range("FTP") - user ^A ^P
-
binary
-
lcd ^R
-
^C
-
bell
-
put ^F
-
bye
Thanx NeoPa for your answer. I'm a novice, so I don't fully grasp it yet, but before asking more dumb questions I'm going to dig in your answer some more.
I'm sure I'll be back with further questions.
Thanks for now.
Chris
NeoPa 32,563
Recognized Expert Moderator MVP
You can use this procedure as a basis for what you need to do to save your CMD & FTP files.
I had to strip out some of my code as it's specific to what I needed and wouldn't suit you. You will need to Copy/Paste the procedure, but you'll also need to make relevant amendments for your situation too.
When the files are prepared and are ready, you just need to execute the CMD file using the Shell() function. - 'WriteFile() creates a text file (strFile) from the data in ranFile.
-
'The file is stored relative to the folder this spreadsheet is found in.
-
Private Function WriteFile(ranFile As Excel.Range, _
-
ByVal strFile As String) As Boolean
-
Dim Various replacement variables as strings
-
Dim strMsg As String
-
Dim intSaveType As Integer
-
Dim ranThis As Excel.Range
-
-
WriteFile = True 'Default to failure
-
'Set up replacement strings
-
Call Workbooks.Add
-
'Use a matching range in the new worksheet that will
-
'take the data from the passed range
-
With Range(...See comment above ...)
-
.Value = ranFile.Value
-
For Each ranThis In .Cells
-
ranThis = Replace(ranThis.Value, "^A", ...)
-
ranThis = Replace(ranThis.Value, "^C", ...)
-
etc
-
Next ranThis
-
End With
-
With ActiveWorkbook
-
strFile = strRootFolder & "\" & strFile
-
On Error Resume Next
-
Kill strFile
-
If Err And Err <> conErrNoFile Then
-
strMsg = Replace("Error(%N) - ""%D""", "%N", Err.Number)
-
strMsg = Replace("Error(%N) - ""%D""", "%D", Err.Description)
-
Call MsgBox(strMsg, vbCritical Or vbOKOnly, "Kill File")
-
Else
-
'I don't know why, but it seems necessary to clear Err
-
Call Err.Clear
-
Call .SaveAs(Filename:=strFile, _
-
FileFormat:=xlTextPrinter, _
-
CreateBackup:=False, _
-
AddToMRU:=False)
-
WriteFile = Err
-
End If
-
On Error GoTo 0
-
Call .Close(SaveChanges:=False)
-
End With
-
End Function
NeoPa 32,563
Recognized Expert Moderator MVP
Thanx NeoPa for your answer. I'm a novice, so I don't fully grasp it yet, but before asking more dumb questions I'm going to dig in your answer some more.
I'm sure I'll be back with further questions.
Thanks for now.
Chris
That's fine Chris. This isn't too basic stuff - I expect some questions.
Hopefully what I've included so far at least has the building blocks to support what you need to accomplish.
PS. If you manage to get this to work for you then you can probably swagger a bit for your boss and colleagues ;)
Hi
This is realy difficult for me. But one step at a time.
Please tell me what the -n , -s and -w in this bit stand for - ECHO ON
-
CD /D "^R"
-
"%SystemRoot%\System32\FTP.Exe" -n -s:^N.Ftp -w:16384 ^S
By the way, there are no collegues or bosses to boast at. I'm just a one-guy operation, doing a hobby beside my regular non-IT job.
Check me out: ** Link removed **
NeoPa 32,563
Recognized Expert Moderator MVP
I was happy to check that out, but I'm afraid we don't allow links to personal web sites in the technical areas so I've removed it from your post.
Of course, pleasant as it was, I couldn't understand too much of it as I can only do ein - tien in Dutch (pretty well) anyway.
NeoPa 32,563
Recognized Expert Moderator MVP
Hi
This is realy difficult for me. But one step at a time.
Please tell me what the -n , -s and -w in this bit stand for - ECHO ON
-
CD /D "^R"
-
"%SystemRoot%\System32\FTP.Exe" -n -s:^N.Ftp -w:16384 ^S
By the way, there are no collegues or bosses to boast at. I'm just a one-guy operation, doing a hobby beside my regular non-IT job.
Check me out: ** Link removed **
No worries. Any questions can be dealt with. As many as you have :) FTP Command Line will give you all you need but :
-n : Suppresses the ability to log on automatically when the initial connection is made. This stops anonymous logon.
-s : Specifies a text file that contains FTP commands. These commands run automatically after FTP starts. This parameter allows no spaces. Use this parameter instead of redirection (<).
-w : Specifies the size of the transfer buffer. The default window size is 4096 bytes. This (default) runs quite slowly in my experience, but probably depends on networking parameters and how many you choose to run in parallel.
Its 23.30 local time, so I will struggle on tomorrow.
Thanks for your answer so far, sorry for the link I shouldn't have posted.
Guess it's probably for the best. People googling my name/trademark could very well stumble upon this thread, wich of course doesn't reflect my proffesional qualities in a very good light :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Harsh Thakur |
last post by:
Hi,
I'd like to know the performance related differences between
Response.Redirect and Server.Transfer.
I'd like to redirect the user to a different page.
I can either do a Response.Redirect("URL") or a Server.Transfer("URL").
So I'd like to find out which is more efficient/better.
Can anyone please tell me or give any pointers to links on...
|
by: Julien C. |
last post by:
Hi all,
I have an "EditeItem.aspx" page which lets me edit properties of an "Item".
In the OnClick() event of my Save button, I do save Item changes to the
database and then I redirect the user to the Item page "ViewItem.aspx" with
a simple :
Server.Transfer("ViewItem.aspx");
I'd like to pass another HTTP parameter so that in the...
|
by: Mark |
last post by:
Hello
I'm trying to use a Server.Transfer in a try-catch (I cannot put it outside the Try-Catch as it is nested deep within a component that is called in a try-catch loop)
The problem is that the Server.Transfer always throws the ThreadAbortException. MSDN acknowledges that this is a unque exception that will be automatically rethrown - i.e....
|
by: Guadala Harry |
last post by:
I've been reading up on Server.Transfer as well as doing some testing, and
it appears to always raise the ThreadAbortException error. On one hand I've
read a bunch of promotional-type material touting the benefits of
Server.Transfer and none of them mention ThreadAbortException - but the MSDN
documentation says Server.Transfer will always...
|
by: Alexander Bosch |
last post by:
Hi,
I'm having a problem similar to the one that's stated in this KB
http://support.microsoft.com/default.aspx?scid=kb;en-us;839521
When I'm posting a page to itself with the bool value as true it falls into
an infinite loop and later a StackOverflow Exception. I need to do this and
not a Response.Redirect or a transfer with the bool in...
| |
by: dee |
last post by:
Hi,
I'm curious why MS decided to have Transfer hide the target page's url
invisible?
Any guesses ?
Thanks.
Dee.
|
by: bryan |
last post by:
I've got a custom HttpHandler to process all requests for a given
extension. It gets invoked OK, but if I try to do a Server.Transfer I
get an HttpException. A Response.Redirect works, but I really need to
avoid the extra round-trip to the client.
I've tried Passing the page name, the full URL, and the instance of
the handler class to the...
|
by: n# |
last post by:
A Basic Question in ASP.NEt 1.1
In Page_Load Event I am doing a Server.Transfer.
But it throws an error on the browser windows showing "Server
Application Not Found"
Pls help me
|
by: evantay |
last post by:
I'm using ASP.NET 2.0 with VS.NET 2005. I'm trying to access properties
from my master pages within a page that inherits from that master page (a
child page). However the values are always null.
In my masterpage I have this:
private bool m_AlreadyTested;
public bool AlreadyTested
{
get { return m_AlreadyTested; }
|
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= |
last post by:
Hi,
I'm using Threads, and when I try to do Server.Transfer, I recieved an
error. (child object does not exist...)
My Code:
Dim t As New Thread(AddressOf Hilo)
Private Sub Hilo()
Thread.Sleep(1000)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |