pConnect->SetCurrentDirectory( "C:\\FilesToSendToServer" ); //Need this set on client, i believe currently setting on server.
CFtpFileFind finder(pConnect);
finder.FindFile( "*", INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_EXISTING_CONNECT );
finder.FindNextFile();
CString filename = finder.GetFileName(); //finds the only file in that directory - test.txt
pConnect->PutFile( filename, "C:\\FilesReceived\\FILE_SENT_FROM_CLIENT.txt", FTP_TRANSFER_TYPE_BINARY, 1 )) //filename set to test.txt correctly
On the client I have the directory FilesToSendToServer with one test file - "test.txt"
I also have the working directory of this application on the client - C\uploadApp\
The code above sets the current directory correctly and "finds" the test file.
However, when PutFile executes with the filename parameter set correctly (test.txt) the functin returns the error file not found.
So as a test, I put a copy of test.txt in the applications working directory uploadApp and it DID send the file to the server.
Why does the file need to be in the working directory to be sent if the active directory is set in the CFtpConnection object?
(Does this mean for any file I want to send from the client I have to copy it over to the directory of the application?)
Thank You.
EDIT
Looks like SetCurrentDirectory calls FtpSetCurrentDirectory which
determine the remote site's current working directory
So for a GET this would make sense...is there an alternate function for a PUT - to set the active directory of the local machine? (FYI - Unable to make a distinction between the remote directory on the server testing on same machine...if testing on target the SetCurrentDirectory should fail, as it is looking on the server...I assume)
It looks like you were meaning to call the win32 API SetCurrentDirectory. This will change the local directory instead of the remote directory that pConnect->SetCurrentDirectory changes. Try ::SetCurrentDirectory if you're in a namespace. Of course your working directory will no longer be C:\uploadApp...
To change the working directory on the client side you should be able to call Win32 ::SetCurrentDirectory.
You will find it easier to get this code working if you get in the habit of checking for errors on any Win32 call, including those encapsulated within MFC.
Related
I have an application that transfers files via socket, desire that this also make transfers directories.
How can I download a full DIRECTORY via socket?
The program works like this, it asks the user to enter the remote directory where the file is to transfer Example: C:\users\server\file.dat
After it makes a validation to confirm the existence of the file,
and finally it transfers byte by byte.
The problem is that when the user type a directory validation fail, an example is if I type C:\users\SERVER\DIRECTORY
the program then returns an error FAILED IN READ BYTES
The solution would be to zip the directory, but the server only works with command line "shell", and Windows has nothing to zip by native command line.
Any suggestions?
You cannot read a directory like an ordinary file. You should search for all files yourself and send them one by one. This means you should also send paths to all files and reproduce their hierarchy yourself.
I want to write a log file for my application. The path where I want to store the file is:
destination::"C:\ColdFusion8\wwwroot\autosyn\logs"
I have used the sample below to generate the log file:
<cfset destination = expandPath('logs')>
<cfoutput>destination::"#destination#"</cfoutput><br/>
<cflog file='#destination#/test' application="yes" text="Running test log.">
When I supply the full path, it didn't create a log file. When I remove my destination, and only provide a file name, the log is generated in the ColdFusion server path C:\ColdFusion8\logs.
How can I generate a log file in my application directory?
Here is the description of attribute file according to cflog tag specs:
Message file. Specify only the main part of the filename. For example,
to log to the Testing.log file, specify "Testing".
The file must be located in the default log directory. You cannot
specify a directory path. If the file does not exist, it is created
automatically, with the extension .log.
You can use cffile tag to write information into the custom folder.
From the docs for <cflog>:
file
Optional
Message file. Specify only the main part of the filename. For example, to log to the Testing.log file, specify "Testing".
The file must be located in the default log directory. You cannot specify a directory path. If the file does not exist, it is created automatically, with the extension .log.
(My emphasis).
Reading the docs is always a good place to start when wondering how things might work.
So <cflog> will only log to the ColdFusion logs directory, and that is by design.
I don't have CF8 handy, but you would be able to set the logging directory to be a different one via either the CFAdmin UI (CF9 has this, I just confirmed), or neo-logging.xml in WEB-INF/cfusion/lib.
Or you could use a different logging mechanism. I doubt it will work on a rusty of CF8 install, but perhaps LogBox?
I am writing a Blackberry 10 Cascades app. I am trying to open a file which is an email attachment.
int in_fd = open(m_uri.replace("file://","").toUtf8().constData(), O_RDONLY);
(There's a reason I am using the open() call)
But the file cannot be opened. I understand that this is to do with sandboxing and app permissions, and that the Invocation framework can make a copy of the file in the target app's directory. What I can't figure out is how to get the path to that file so that I can open it.
I need to know:
How to make sure the Invocation Framework copies the file to my apps sandbox on invocation.
How to access the resulting copied file.
In C++
Can you print an example of what is contained inside m_uri when your code runs?
If the path you are feeding open() does not have a leading /, then it will look from the app's home directory which is not what you want.
I need to create a temp file in a specified folder on MAC. However I am able to create the folder at the correct location but not able to create the file inside. I get an error saying it does not have permissions to create the file although i have passed 777 as file permission while creating the folder. please find my code below. I would like to mention that this problem is only on MAC. On windows it executes as expected. please let me know what the issue is.
wxString curDir = SeeWorkingDir() + wxT("Temp\\"); //Gets the working directory
if(!wxFileName::DirExists(curDir)) //Checks if directory exists
wxFileName::Mkdir( curDir, 0777, wxPATH_MKDIR_FULL ); // creates the directory
wxString jobcopy = wxFileName::CreateTempFileName(curDir); // should create temp file
I have absolutely no idea what your "SeeWorkingDir()" function is returning, but if it's returning the application directory then you shouldn't be writing anything into there.
Why not replace "SeeWorkingDir()" with a path to somewhere on the Macintosh that truly is writable, like the "/tmp/" directory?
You have not explained what your function SeeWorkingDir() does.
Maybe you should use wxFileName::GetTempDir to specify the directory where you store the file. This should be platform independent.
Or, in your call wxFileName::CreateTempFileName(curDir), you could specify the fileTemp parameter to open the file directly.
See the documentation:
wxWidgets 2.8.12 - wxFileName
I have written a c++ program and deployed it in say c:\my_app, and my executable's path is c:\my_app\my_app.exe. Say, my_app needs many files such as the_file.txt, which is located in c:\my_app\the_file.txt.
In my executable, I open the txt file as, xx.open("the_file.txt");
Moreover, I have associated my program with let's say .myp extension.
When I'm on Desktop, and want to open a file named example.myp, my program can not see the_file.txt. Because, it (somehow) assumes that it's currently working on Desktop.
Is there any easy way to handle this problem by changing shell command for open in HKEY_CLASSES_ROOT? The naive solution would be to change all file open operations with something like %my_app_location/the_file.txt". I don't want to do that.
Always use a full path name to open a file. In other words, don't open "foo.txt", open "c:\bar\foo.txt". To find the install directory of your EXE use GetModuleFileName(), passing NULL for the module handle.
These days you shouldn't add files to c:\my_app....
Instead use the ProgramData Folder and full paths.
Use SHGetSpecialFolderPathA with CSIDL_COMMON_APPDATA to get the ProgramData folder and the create your program directory and add your files.
You should set current directory for your app's folder with SetCurrentDirectory function. After that you can open file by name without full path