Sending a file through FTP to a share-drive (UNC) - vba

I have a particular file which needs to be sent to a share drive location through FTP.
I know there is a method by writing contents on a flat file and executing with shell script. Sadly that is not working since my send location is weird and I don't know how to interpret it, its like this.
//corporate.abc.com/data/ac/ny/log
I have no idea what the above thing means. Is there any way to send data to that location?
PS: I opened it through my Windows Run command and its opening up. It is not asking for any user authentication.
Update: I tried to open using explorer but I am getting error" runtime error 75 , path/file access error"
Sub FtpFileto()
Dim vFile As String
Dim vFTPServ As String
Dim fNum As Long
vPath = "C:\macro/pop.txt"
vFile = "C:\macro/post.xlsx"
vFTPServ = "corporate.abc.com"
Open "//corporate.abc.com/data/NA/US/OC/Common/HOSTDL/CatSpec" For Output As #1
Close
Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbNormalNoFocus
End Sub

If the UNC path can be opened in Windows Explorer, it means that it is directly accessible and can be worked with as if it were a local path.
Open "\\corporate.abc.com\data\ac\ny\log\test.ext" For Output As #1
Write #1, Data
Close #1
You do not need (cannot) use FTP to work with it.
Note that the UNC is a Windows convention, so it uses backslashes, not forward slashes (though in many cases Windows will accept the forward slashes too).

Related

VBA to open Sharepoint folder in Windows Explorer, not Internet Explorer

I'm trying to create a button in MS Access to open a Sharepoint folder in Windows Explorer, not Internet Explorer. I had it working momentarily, and don't know what broke. This currently opens the sharepoint folder in Internet Explorer.
Dim Foldername As String
Foldername = "http://vaww.visn21.portal.va.gov/sanfrancisco/education/EDADMIN/Service Timekeeping Records\"
Shell "C:\WINDOWS\explorer.exe """ & Foldername & "", vbNormalFocus
Edit: I have also tried this code, same effect where it opens it in internet explorer, not windows explorer.
Dim path As String
path = "http://vaww.visn21.portal.va.gov/sanfrancisco/education/EDADMIN/Service Timekeeping Records\"
Shell "cmd /C start """" /max """ & path & """", vbHide
End Sub
Edit 2 : Tried this code, still just opens internet explorer instead of windows explorer
Call Shell("explorer """"" & "http://vaww.visn21.portal.va.gov/sanfrancisco/education/EDADMIN/Service Timekeeping Records\" & """""", vbNormalFocus)
Ideally this will be used as the primary interface to access these folders once their names are changed to program numbers instead of program names (And thus the links won't break every time a program name changes).
So I don't know WHY this works, I think it has something to do with the difference between forward slashes and backslashes, but here's the code that wound up working. This code checks to see if a particular folder exists, creates the folder if it does not, and then tries to open the folder in Windows Explorer, not internet explorer.
Private Sub ButtonMkDirTest_Click()
myWorkBookBasePath = "\\vaww.visn21.portal.va.gov\sanfrancisco\education\EDADMIN\TESTFOLDER"
If Len(Dir(myWorkBookBasePath, vbDirectory)) = 0 Then
MkDir myWorkBookBasePath
End If
Dim path As String
path = myWorkBookBasePath
Shell "cmd /C start """" /max """ & path & """", vbHide
End Sub
Watch out for that http protocol, it'll kill you every time!
No one else seems interested in this topic, probably for the best of reasons. You have to be - politely put - eccentric to try to open an internet address with a local disk utility.
Windows Explorer is designed to open local folders only. Windows is designed around a series of protocols, principally the http: protocol, but also the file: protocol. There are others, but for the current topic those are the important two.
The http: protocol is designed to open Internet Explorer, and the file: protocol is designed to open Windows Explorer. There are a whole bunch of Registry keys which control this behaviour.
In the current question, the poster has specified http: as part of the target address, in the case which resulted in Internet Explorer opening. That occurred even though Internet Explorer was not specified on the command line, because when Windows encounters a http: address, the Registry is set up to cause Internet Explorer to run.
In the second case, where the o/p was puzzled by Windows Explorer opening, if you look closely at his second command you'll notice that this 2nd command does not expressly mention http: in the command, which was why the http: protocol did not take over the handling of the command (so Internet Explorer was not called).

Error on the remote server: 227 Entering Passive Mode(xxx,xxx,xxx,xx)

I tried to download a .bak file from the FTP and save it into a local directory in my pc.
This is my code:
Try
My.Computer.Network.DownloadFile("ftp://nameOfServer/file.bak", "C:\Users\Admin\Documents\BackUp\file.bak", "user", "password")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
End Try
When I execute the code I get this error:
Error on the remote server: 227 Entering Passive Mode(xxx,xx,xxx,xxx,xxx,xx)
I know that I need to change it to active mode, but I canĀ“t find a way works correctly with my code.
How can I solve that? thanks
You should make sure you are downloading the files correctly by following this older edit.
After some fiddling around to recreate the issue, the issue was solved
using the following code
Dim username As String = "username"
Dim password As String = "password"
Dim address As String = "address"
Dim file As String = "file"
Dim outputFile As String = "outputFile"
My.Computer.Network.DownloadFile("ftp://" + username + ":" + password + "#" + address + "/" + file, outputFile)
Or the following was more concisely able to solve the issue
My.Computer.Network.DownloadFile("ftp://username:password#address/file", "outputLocation")
But another possible cause for your problems may have been simply caused by the output directory being missing, or more likely write protected (either by security policies or folder settings).
Finally if you have everything correct code and file-structure wise, I would advise contacting the ftp provider, and make sure the ftp server is configured and optimized properly for your use. If you cannot contact your ftp provider for help yet you can access your ftp settings, I would recommend disabling passive mode all-together for your ftp server at your own risk.

Able to write file but not read from a network location

I have following network location
Dim myfolder As String = "\\10.0.0.90\myfolder\"
I am able to create a new file in this folder using following code:
File.Create (myfolder)
But when I try to read contents of this folder using code below I get error.
Code
Dim orderedFiles = New System.IO.DirectoryInfo(myfolder).GetFiles()
Error
The system detected a possible attempt to compromise security. Please
ensure that you can contact the server that authenticated you.
File writing is being done by ASP.Net page while reading is done from Windows Service. Could this be the issue?
Windows Service was running as "Local System". I right click on it, went into properties and changed the "Log on as" to some user account and now it can access network folder.

Opening a file from a web app VB.NET

I am currently trying to open a file on my web app by retrieving the file path from a sql database
here is my code that will open the file when I double click an index in a listbox.
Protected Sub userdoubleClick()
Dim selectedPath As String
Try
fileConnection.Open()
selectedFile = FileListBox.SelectedValue
'takes the selected items from the listbox and searches the database for the file
'and will open the file for the user
fileCommand.CommandText = "SELECT filePath FROM ImportedFiles WHERE FileName = '" & selectedFile & "'"
fileDataReader = fileCommand.ExecuteReader
Do While fileDataReader.Read
selectedPath = fileDataReader.GetValue(0)
Loop
System.Diagnostics.Process.Start(selectedPath)
Catch ex As Exception
End Try
fileConnection.Close()
End Sub
When I run this on my local PC it works fine but then when I publish it to a server it wont open the file.
System.Diagnostics.Process.Start(selectedPath) will open the file on the machine running the web application; in other words, it is opening it on your local machine when running locally, but opening on the server when deployed. This just isn't going to work.
See ASP.Net Download file to client browser
If you're accessing the files from a web application, then the user identity under which the file is opened is not that of the user logged into your application. It's the user under which the IIS application pool is running. That's the user that needs to have permission granted to your shared drive.
There are many solutions to this problem, including changing the context under which the application pool is running or making the files local.

FolderBrowseDialog to browse folder of server computer from client computer

I want to open the directory of server computer using FolderBrowserDialog from the client machine.
Is it possible?
I have searched for it n haven't found the solution.
I have found others such as to browse Network Folders, here: How-to-Browse-Network-Folders-using-Folder-Dialog .
But i am looking for to browse the directory of server from the client.
here is a snippet that works fine with .net 4:
Dim dlg As New FolderBrowserDialog()
dlg.SelectedPath = "\\yourServer\share"
If dlg.ShowDialog() = DialogResult.OK Then
Dim selected = dlg.SelectedPath
' ...
End If
no need for RootFolder or any hacking - this will open the dialog on my computer (both client/server are windows-OS in a windows-domain) at the network-share and let my trill down into the folders there - at the end you will get a string like \\yourServer\share\selected\path back