Answers.Body: <p>Craft 2 doesn't really have the concept of sessions or logging in for it's console app.</p>
  
  <p>If I had to guess that error is more about file system permissions, but you'd want to check your log files for a full stack trace to see where it's originating from.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-30T05:31:35.113Z
Answers.LastActivityDate: 2015-07-30T05:31:35.113Z
Answers.UserDisplayName: Brad Bell
Body: <p>I am writing a console plugin to import a load of gallery images from an old site into a new craft site. I need to create folders in the assets area, import the images, then create custom entries to represent the galleries.</p>
  
  <p>I am hitting a hurdle at the first task, creating a folder. It fails with a general message like "Error creating folder". I assume it's because I am not "logged in" and therefore have no permission to create the assets folder.</p>
  
  <p>So I tried to do a <code>craft()-&gt;userSession-&gt;loginByUserId(1)</code> but I got the complaint about no ip address or user agent string. I checked the code and saw that there is a config item to turn this check off, but the method <code>loginByUserId()</code> doesn't use it.</p>
  
  <p>Is there a way to force a login from a console plugin so that I can do privileged operations?</p>
  
Tags: <plugin-development>
Title: "Logging In" From a Console Plugin?
ThreadText: # "Logging In" From a Console Plugin?
  
  (Asked by: username_0 on 2015-07-29)
  
  I am writing a console plugin to import a load of gallery images from an old site into a new craft site. I need to create folders in the assets area, import the images, then create custom entries to represent the galleries.
  
  I am hitting a hurdle at the first task, creating a folder. It fails with a general message like "Error creating folder". I assume it's because I am not "logged in" and therefore have no permission to create the assets folder.
  
  So I tried to do a `craft()->userSession->loginByUserId(1)` but I got the complaint about no ip address or user agent string. I checked the code and saw that there is a config item to turn this check off, but the method `loginByUserId()` doesn't use it.
  
  Is there a way to force a login from a console plugin so that I can do privileged operations?
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-07-30. Score: 2 | Accepted answer
  
  Craft 2 doesn't really have the concept of sessions or logging in for it's console app.
  
  If I had to guess that error is more about file system permissions, but you'd want to check your log files for a full stack trace to see where it's originating from.
  
  
  ---
  
  