FTP upload of exploration results doesn't work

Hello,

I am trying to upload exploration results as xls, csv or txt files to my website server using FTP. To do so, I first created a network location on my PC (I am using windows 7) and I save the exploration result to that folder. I can drag or copy/paste files from my computer into that new network folder without a problem, so the folder is set up correctly.
Sharing options are set up correctly too.

My AFL code for the exploration which saves results to a folder is identical to the one shown here:
//http://www.amibroker.com/kb/tag/export/

except that the network location file path is

filepath = “C:\Users\User1\AppData\Roaming\Microsoft\Windows\Network Shortcuts\TEST_for_Amibroker\Example2.csv”

Moderator comment: READ THE FORUM RULES before posting and use CODE TAGS. Without code tags your code formatting is destroyed.

which was assigned by the Windows Network Location Wizard.

When using the filepath C:\ScanExport.txt, it saves to the C drive without a problem. However, when using the file path of the network folder, it doesn’t seem to save as the file with the exploration results doesn’t appear in the folder.

Why can’t AB save the file to the network folder?

I am also able to save the results in Google Drive which has this file path: C:\Users\User1\Google Drive

Any help with this would be greatly appreciated. Thank you.

@Mojotrader check the documentation of the fopen() function.

Just a basic check: do you use DOUBLE BACKSLASH (from the docs: “Please note that single backslash in path must be written in AFL as (double backslash”) and do you check the function return code?

filepath = "C:\\Users\\User1\\AppData\\Roaming\\Microsoft\\Windows\\Network Shortcuts\\TEST_for_Amibroker\\Example2.csv"

hello

to sent (save) files to the Network you must use 4 backslash

//  \\\\Panos-win7pc\\network\\     
//  to sent files to the Network you must use 4 backslash

fh = fopen( "\\\\Panos-win7pc\\NetWork\\"+Name()+newtickerName+".txt", "w"); 
3 Likes

@Panos, Thank you for your clarification.
In this case, however, it seems that he mapped the destination folder via a shortcut created with the Windows Network Location Wizard (I do not see a \ - double backslash - in the path he posted).

More in general, personally I will directly create a short-named network share (all lowercase without any space in the name to avoid other possible issues) and will check the user permission rights to ensure that the needed users and/or processes will have the rights to access it in write/read mode as required (but this is more related to networking settings in Windows than directly to AmiBroker).
(…and if possible I will also avoid using the %appdata% folder)

But, let’s see if our suggestions will solve the problem: there is also the possibility that the issue is elsewhere!

1 Like

@beppe Thank you too

Giuseppe if its allowed I am going to drop few words here, for users that find difficult to find the Network path.

This is my steps (tested and working)

  1. I open System properties to see the Computer Name of my other PC No2 (In there I try to type a PC Name easy to remember, in my case is Panos-win7pc)
  2. In PC No1 where is myAmibroker AFL we type the Computer name of PC No2 with 4 backslash
\\\\Name_Of_PC_No2\\harddrive\\Folder

That’s all. Without shortcuts

fh = fopen( "\\\\Panos-win7pc\\harddrive\\Folder\\" +Name()+".txt", "w");

@Panos and @Beppe, thanks for your kind help. I use double backlash. I also tried 4 backlash , i.e. C:\\ but it doesn't work. Both

filepath = "C:\\Users\\User1\\AppData\\Roaming\\Microsoft\\Windows\\Network Shortcuts\\TEST_for_Amibroker\\Example2.csv"

and

filepath = "C:\\\\Users\\User1\\AppData\\Roaming\\Microsoft\\Windows\\Network Shortcuts\\TEST_for_Amibroker\\Example2.csv"

don't work. The example given at
http://www.amibroker.com/kb/tag/export/
also uses 2 backlashes and my code is basically the same except for the file path. Regarding user rights, I checked them and they are OK as I can save files there.
I can drag and drop files into this neetwork folder and I can also save Excel or Word documents directly form Word or Excel in that folder. However, I cannot save Amibroker files, e.g. formulas, templates etc directly from Amibroker in that folder. Also, if you look at the screenshots below, the upper window is from Word 2003 and you can see two Network folders whereas in Amibroker you can't.
Untitled-2

I really don't know what's going on here.

BTW, I also noticed that in Word etc, when you save a file and click on 'Computer', you can see the Network folders whereas in Amibroker, they don't show up:

Untitled-3

@Mojotrader did you tried to access the network folder directly (without the local mapping created with the Wizard) as suggested by @PanoS?

Yes, I can access it without a problem. I can only not access it from Amibroker. I have been searching the Internet if others had similar problems with other software and it seems to be the case:

I mean to try using the network address directly NOT the shortcut.

If you click on your network shortcut with the right mouse button and choose the "Properties" popup menu item a dialog will show up similar to this one:

immagine

The "Target:" is the path to use in your code (fix the backslashes and add the filename before using it in your code).

@Panos and @Beppe, I tried that too but it didn’t work. But I found a workaround. After I unsuccessfully tried it by mapping a web drive, I used a program called WebDrive which does pretty much the same as mapping a webdrive using Windows with the only difference that it actually worked for me. I basically followed the steps shown here:

The file path now is
z:\\TEST_for_Amibroker\\Example1.csv

I don’t know why it doesn’t work when mapping it with the Windows wizard.

I now can upload Exploration results directly to my website and publish them as tables and charts.
Thanks again for your help!

FTP and mapped network drive are completely two different things. FTP is Unix File Transfer Protocol and is implemented by Internet Explorer (and Windows explorer because Windows explorer shares many components with Internet Explorer). FTP access in explorer is not implemented on file system level.

To write to FTP location you need formal implementation of FTP UPLOAD. It won’t work with fopen() because fopen is C runtime function that works with LOCAL files, not remote ones. fopen() runtime function calls Windows API CreateFile that does NOT support FTP. https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx

To access FTP from Windows API there are separate functions in Windows Internet API (used by Internet Explorer and Windows Explorer): https://msdn.microsoft.com/en-us/library/windows/desktop/aa384157(v=vs.85).aspx and https://msdn.microsoft.com/en-us/library/windows/desktop/aa384170(v=vs.85).aspx

Mapped network drives in Windows are completely different story.

They are implemented by SAMBA protocol. Samba in windows allows WRITING to remote directory via file system because file system in Windows integrates with samba. So you should be able to write to SAMBA drive (network share) via fopen() without problems.

Solution: use SAMBA drive (windows file sharing) instead of FTP

2 Likes