tags:

views:

160

answers:

3

i need to be able to SFTP though VBA. I have an Access program that pulls data, manipulates it and now i have to find a way to upload the excel 07 file through SFTP.

i've been looking on the net for days and can't find anything. I saw a similar topic here http://stackoverflow.com/questions/202197/how-to-use-sftp-from-within-an-ms-access-database-module, and i'd love to find Mat Nadrofsky, because it seemed like he has a solution, i just cant understand any of it)))))))))))

so if someone can explain what that solution was about or has a different solution - i'd really appreciate it thank you

A: 

I have done it the following way in Access 97:

  1. Buy a SFTP client that has an OCX that is available to MS Access
  2. Write VBA code to use the SFTP control

In one particular case, there was no OCX - only executable - we had to do a batch file for that one.

Raj More
thank you, as i said belowe, my company won't pay for that, so i'm trying to see if there's anything i can do by code. it seemd like on the link i'm giving in my post they found a solution, i just don't have enough knowledge to pick up what they meant
lalachka
You will probably end up spending more time on building something yourself than just buy an off the shelf component. Build-vs-Buy
Raj More
true, and in some cases it's worth it to buy it, but in the process i also get to learn a lot, and second of all, in this case i don't have a choice. i need to automate one step that i can otherwise do by hand. my company will never pay for that and i'd totally understand. anyhow, i got it to work.
lalachka
sorry, second thought, i got it to work by using PUTTY, so i didn't build anything myself, so you're right. it's just that PUTTY is free. you are right in this case 100% because i could never build anything like this on my own. i was hoping to find some code on the net that i can customize.
lalachka
A: 

You would need some SFTP ActiveX Control that works in Access. I know that our SFTP control is used by some customers in VBA and in Access in particular.

Eugene Mayevski 'EldoS Corp
i saw your site before and it looks like it'd work for me, except for i need this done to save me a few steps that i can otherwise do by hand and my company will never pay for that))))) thanks anyway
lalachka
A: 

In the previous SO answer you linked, Mat Nadrofsky used an sftp command line client. In this example my sftp client is pscp.exe. That client is part of the PuTTY tools: PuTTY Download Page

I want to build and run a command like this to copy sample.txt to my home directory on the remote machine:

"C:\Program Files\PuTTY\pscp.exe" -sftp -l hans -pw changeme C:\Access\sample.txt 192.168.1.6:/home/hans/

So this procedure will build and run that command string.

Public Sub SftpPut()
    Const cstrSftp As String = """C:\Program Files\PuTTY\pscp.exe"""
    Dim strCommand As String
    Dim pUser As String
    Dim pPass As String
    Dim pHost As String
    Dim pFile As String
    Dim pRemotePath As String

    pUser = "hans"
    pPass = "changeme"
    pHost = "192.168.1.6"
    pFile = "C:\Access\sample.txt"
    pRemotePath = "/home/hans/"

    strCommand = cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & _
        " " & pFile & " " & pHost & ":" & pRemotePath
    Debug.Print strCommand
    Shell strCommand, 1 ' vbNormalFocus '
End Sub

You may prefer ShellAndWait instead of Shell, as David Fenton suggested in a comment on the previous answer.

HansUp
first of all, thank you so much. i was able to find the guy from the link post and he told me about putty and i was able to get it to work with putty and ShellAndWait. your VBA code is much better than mine though))))))))))))) One problem, it works on a company laptop from home but not from work. i'm sure something is blovking it, and i asked IT to see what it is, but it's been days, he tried a few things and i have a feeling he will come back and say "Upload by hand". so i'm not sure where i am now, if it's being blocked because of putty or what
lalachka
i just noticed something, you're using pscp.exe. i was using psftp.exe, also from Putty. Is there a chance that pscp.exe won't be blocked and psftp.exe is? it seems unlikely to me, but i'm desperate to have the whole thing automated and ready to try anything. it just seems wrong to me to have a program that's automated down to a click and then sftp by hand. i hope someone understands.
lalachka
Are you able to upload with sftp by any method from your workplace network? If not, my guess is the sftp port is blocked there. I doubt pscp.exe vs. psftp.exe would make a difference, but you can try switching anyway. What response do you see in the shell window when it doesn't work?
HansUp
i'm able to sftp by hand, meaning just going to their site in internet explorer, clicking upload and so on. if it helps when i type "telnet 44.44.44.44 22" at the command prompt i get nothing, everything disappears and the window is just black, so it's not connecting. and here's everything i get after typing psftp connection string at the command promptLooking up host "sftp.ffffff.com"Connecting to 44.44.44.44 port 22Network error: Software caused connection abortFatal: Network error: Software caused connection abortand thank you so much for your time
lalachka
I'm not sure what connecting with IE tells you ... perhaps the sftp port is proxied for http. From Windows when I `telnet 192.168.1.6 22`, I get a response SSH-2.0-OpenSSH_4.3 from the Linux server. But you get nothing on your workplace network. What telnet response do you get from home, where psftp.exe works?
HansUp
SSH-2.0-1.36_sshlib GlobalSCAPEthis is what i get from home and as far as i know, this is what's supposed to show up. So i'm almost sure something is blocking it at work but it doesn't look like IT is doing anything about it, it's been over a week since i asked them. so thank you for your lesson and your time, at least i learned how to do it
lalachka
hi, i hope you're still around and will read this. IT finally unblocked whatever was blocked and i got it to work. Now last step, i'm using ShellAndWait from here http://www.cpearson.com/excel/ShellAndWait.aspx and it's not working for me, i keep getting 1 returned (which means the command didn't work in Windows). But when i paste my cmdLine into Start, Run box it runs fine. Any ideas? I'm using Excel for this, and the link you gave for the ShellAndWait code is not working for me for some reason. Should i make this into a separate topic?
lalachka
Without more to go on, I will guess your problem now is something specific to ShellAndWait. So, yes, post a separate question.
HansUp
sure, i just wanted to make sure i get your attention))))))))))
lalachka